Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added @sessionist-maintain-path option #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
8 changes: 8 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 11 additions & 5 deletions scripts/new_session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,11 +28,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_named_session "$pane_current_path" "$SESSION_NAME")
switch_to_session "$session_id"
fi
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/promote_pane.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions scripts/promote_window.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down