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

[deleted] #28

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Sessions are a second class citizen in tmux environment:

This plugin solves the above problems.

### Features
### Key Bindings

- `prefix + g` - prompts for session name and switches to it. Performs 'kind-of'
name completion.<br/>
Expand All @@ -32,7 +32,19 @@ This plugin solves the above problems.
- secondary-keys
- `h`, `-`, `"`: join horizontally
- `v`, `|`, `%`: join vertically
- `f`, `@`: join full screen
- `f`, `@`: join full screen

To change these, add to `.tmux.conf`:

set -g @sessionist-goto 'C-f'
set -g @sessionist-alternate 'P'
set -g @sessionist-new 'C-c'
set -g @sessionist-promote-pane 'b'
set -g @sessionist-promote-window 'B'
set -g @sessionist-join-pane 'no-key'
set -g @sessionist-kill-session 'C-x'

instad, to unbind, simply set the variable to arbitrary text (e.g. `no-key`)

### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)

Expand Down
43 changes: 43 additions & 0 deletions scripts/promote_window.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source "$CURRENT_DIR/helpers.sh"

# global vars passed to the script as arguments
CURRENT_SESSION_NAME="$1"
CURRENT_WINDOW_ID="$2"
CURRENT_WINDOW_NAME="$3"
WINDOW_CURRENT_PATH="$4"

number_of_windows() {
tmux list-windows -t "$CURRENT_SESSION_NAME" |
wc -l |
tr -d ' '
}

create_new_session() {
TMUX="" tmux -S "$(tmux_socket)" new-session -c "$WINDOW_CURRENT_PATH" -s "se-$CURRENT_WINDOW_NAME" -d -P -F "#{session_name}"
}

new_session_window_id() {
local session_name="$1"
tmux list-windows -t "$session_name" -F "#{window_id}"
}

promote_window() {
local session_name="$(create_new_session)"
local new_session_window_id="$(new_session_window_id "$session_name")"
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"
}

main() {
if [ "$(number_of_windows)" -gt 1 ]; then
promote_window
else
display_message "Can't promote with only one window in session"
fi
}
main
13 changes: 13 additions & 0 deletions sessionist.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ tmux_option_new="@sessionist-new"
default_key_bindings_promote_pane="@"
tmux_option_promote_pane="@sessionist-promote-pane"

default_key_bindings_promote_window="C-@"
tmux_option_promote_window="@sessionist-promote-window"

default_key_bindings_join_pane="t"
tmux_option_join_pane="@sessionist-join-pane"

Expand Down Expand Up @@ -59,6 +62,15 @@ set_promote_pane_binding() {
done
}

# "Promote" the current window to a new session
set_promote_window_binding() {
local key_bindings=$(get_tmux_option "$tmux_option_promote_window" "$default_key_bindings_promote_window")
local key
for key in $key_bindings; do
tmux bind "$key" run "$CURRENT_DIR/scripts/promote_window.sh '#{session_name}' '#{window_id}' '#{window_name}' '#{pane_current_path}'"
done
}

set_join_pane_secondary_bindings() {
local secondary_key_table="$1"
local break_pane_flag="$2"
Expand Down Expand Up @@ -103,6 +115,7 @@ main() {
set_alternate_session_binding
set_new_session_binding
set_promote_pane_binding
set_promote_window_binding
set_join_pane_binding
set_kill_session_binding
}
Expand Down