Skip to content

Commit 933672b

Browse files
committed
feat: added @sessionist-maintain-path option
moved create_new_session() to helpers
1 parent a315c42 commit 933672b

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

scripts/helpers.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,11 @@ switch_to_session() {
5252
local session_name="$1"
5353
tmux switch-client -t "$session_name"
5454
}
55+
56+
create_session() {
57+
if [ "$(get_tmux_option "@sessionist-maintain-path")" == "on" ]; then
58+
TMUX="" tmux -S "$(tmux_socket)" new-session -c "$1" -d -P -F "#{session_id}"
59+
else
60+
TMUX="" tmux -S "$(tmux_socket)" new-session -d -P -F "#{session_id}"
61+
fi
62+
}

scripts/new_session.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ create_new_tmux_session() {
2020
else
2121
# New session name may differ from the input. Eg input name may be
2222
# 'foo.bar', but new name will be 'foo_bar'.
23-
#
24-
# -c "#{pane_current_path}" has to be specified, otherwise a random path is
25-
# used for the new session.
26-
local session_name=$(TMUX="" tmux -S "$(tmux_socket)" new-session -d -P -c "#{pane_current_path}" -s "$SESSION_NAME")
27-
switch_to_session "$session_name"
23+
local pane_current_path=$(tmux display-message -p "#{pane_current_path}")
24+
local session_id=$(create_session "$pane_current_path")
25+
switch_to_session "$session_id"
2826
fi
2927
}
3028

scripts/promote_pane.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ new_session_pane_id() {
2525
}
2626

2727
promote_pane() {
28-
local session_name="$(create_new_session)"
29-
local new_session_pane_id="$(new_session_pane_id "$session_name")"
28+
local session_id="$(create_session "$PANE_CURRENT_PATH")"
29+
local new_session_pane_id="$(new_session_pane_id "$session_id")"
3030
tmux join-pane -s "$CURRENT_PANE_ID" -t "$new_session_pane_id"
3131
tmux kill-pane -t "$new_session_pane_id"
32-
switch_to_session "$session_name"
32+
switch_to_session "$session_id"
3333
}
3434

3535
main() {

scripts/promote_window.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ new_session_window_id() {
2626
}
2727

2828
promote_window() {
29-
local session_name="$(create_new_session)"
30-
local new_session_window_id="$(new_session_window_id "$session_name")"
29+
local session_id="$(create_session "$WINDOW_CURRENT_PATH")"
30+
local new_session_window_id="$(new_session_window_id "$session_id")"
3131
tmux swap-window -s "$CURRENT_WINDOW_ID" -t "$new_session_window_id"
3232
tmux kill-window -t "$new_session_window_id"
33-
switch_to_session "$session_name"
33+
switch_to_session "$session_id"
3434
}
3535

3636
main() {

0 commit comments

Comments
 (0)