From 933672b8866d51190ef305e1ec6ddfd81317fb2b Mon Sep 17 00:00:00 2001 From: TheSast <27977196+TheSast@users.noreply.github.com> Date: Fri, 12 May 2023 18:13:02 +0200 Subject: [PATCH 1/3] feat: added @sessionist-maintain-path option moved create_new_session() to helpers --- scripts/helpers.sh | 8 ++++++++ scripts/new_session.sh | 8 +++----- scripts/promote_pane.sh | 6 +++--- scripts/promote_window.sh | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/scripts/helpers.sh b/scripts/helpers.sh index dd02934..f5a68ee 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -52,3 +52,11 @@ switch_to_session() { local session_name="$1" tmux switch-client -t "$session_name" } + +create_session() { + if [ "$(get_tmux_option "@sessionist-maintain-path")" == "on" ]; then + TMUX="" tmux -S "$(tmux_socket)" new-session -c "$1" -d -P -F "#{session_id}" + else + TMUX="" tmux -S "$(tmux_socket)" new-session -d -P -F "#{session_id}" + fi +} diff --git a/scripts/new_session.sh b/scripts/new_session.sh index db41b42..7184a22 100755 --- a/scripts/new_session.sh +++ b/scripts/new_session.sh @@ -20,11 +20,9 @@ create_new_tmux_session() { else # New session name may differ from the input. Eg input name may be # 'foo.bar', but new name will be 'foo_bar'. - # - # -c "#{pane_current_path}" has to be specified, otherwise a random path is - # used for the new session. - local session_name=$(TMUX="" tmux -S "$(tmux_socket)" new-session -d -P -c "#{pane_current_path}" -s "$SESSION_NAME") - switch_to_session "$session_name" + local pane_current_path=$(tmux display-message -p "#{pane_current_path}") + local session_id=$(create_session "$pane_current_path") + switch_to_session "$session_id" fi } diff --git a/scripts/promote_pane.sh b/scripts/promote_pane.sh index 4d27a4c..add73e0 100755 --- a/scripts/promote_pane.sh +++ b/scripts/promote_pane.sh @@ -25,11 +25,11 @@ new_session_pane_id() { } promote_pane() { - local session_name="$(create_new_session)" - local new_session_pane_id="$(new_session_pane_id "$session_name")" + local session_id="$(create_session "$PANE_CURRENT_PATH")" + local new_session_pane_id="$(new_session_pane_id "$session_id")" tmux join-pane -s "$CURRENT_PANE_ID" -t "$new_session_pane_id" tmux kill-pane -t "$new_session_pane_id" - switch_to_session "$session_name" + switch_to_session "$session_id" } main() { diff --git a/scripts/promote_window.sh b/scripts/promote_window.sh index 9d93e0d..4fec918 100755 --- a/scripts/promote_window.sh +++ b/scripts/promote_window.sh @@ -26,11 +26,11 @@ new_session_window_id() { } promote_window() { - local session_name="$(create_new_session)" - local new_session_window_id="$(new_session_window_id "$session_name")" + local session_id="$(create_session "$WINDOW_CURRENT_PATH")" + local new_session_window_id="$(new_session_window_id "$session_id")" tmux swap-window -s "$CURRENT_WINDOW_ID" -t "$new_session_window_id" tmux kill-window -t "$new_session_window_id" - switch_to_session "$session_name" + switch_to_session "$session_id" } main() { From f0c8041649efc41efa92c4a0a08290089a8e837a Mon Sep 17 00:00:00 2001 From: TheSast <27977196+TheSast@users.noreply.github.com> Date: Fri, 12 May 2023 18:14:59 +0200 Subject: [PATCH 2/3] docs: added how to set @sessionist-maintain-path --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f66ba57..3d623f9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ This plugin solves the above problems. - `v`, `|`, `%`: join vertically - `f`, `@`: join full screen +### Configuration + +If you wish for sessions created by promoting a pane or window use their path add this to `.tmux.conf`: + + set -g @sessionist-maintain-path 'on' + ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) Add plugin to the list of TPM plugins in `.tmux.conf`: From 06f857f02c8be31eed40b45754bd238c5a22c677 Mon Sep 17 00:00:00 2001 From: TheSast <27977196+TheSast@users.noreply.github.com> Date: Fri, 12 May 2023 19:17:57 +0200 Subject: [PATCH 3/3] fix: new session not naming correctly --- scripts/new_session.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/new_session.sh b/scripts/new_session.sh index 7184a22..707132e 100755 --- a/scripts/new_session.sh +++ b/scripts/new_session.sh @@ -11,6 +11,14 @@ session_name_not_provided() { [ -z "$SESSION_NAME" ] } +create_named_session() { + if [ "$(get_tmux_option "@sessionist-maintain-path")" == "on" ]; then + TMUX="" tmux -S "$(tmux_socket)" new-session -c "$1" -s "$2" -d -P -F "#{session_id}" + else + TMUX="" tmux -S "$(tmux_socket)" new-session -s "$2" -d -P -F "#{session_id}" + fi +} + create_new_tmux_session() { if session_name_not_provided; then exit 0 @@ -21,7 +29,7 @@ create_new_tmux_session() { # New session name may differ from the input. Eg input name may be # 'foo.bar', but new name will be 'foo_bar'. local pane_current_path=$(tmux display-message -p "#{pane_current_path}") - local session_id=$(create_session "$pane_current_path") + local session_id=$(create_named_session "$pane_current_path" "$SESSION_NAME") switch_to_session "$session_id" fi }