├── .gitattributes ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── screenshots ├── gif_source.pdf ├── sessions_list.png └── tmux_goto_session.gif ├── scripts ├── goto_session.sh ├── helpers.sh ├── join_pane.sh ├── kill_session.sh ├── kill_session_prompt.sh ├── list_sessions.sh ├── new_session.sh ├── new_session_prompt.sh ├── promote_pane.sh ├── promote_window.sh └── switch_or_loop.sh └── sessionist.tmux /.gitattributes: -------------------------------------------------------------------------------- 1 | # Force text files to have unix eols, so Windows/Cygwin does not break them 2 | *.* eol=lf 3 | 4 | *.gif binary 5 | *.pdf binary 6 | *.png binary 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### master 4 | - handle "promote pane" feature bug 5 | - add `.gitattributes` file so that end of line chracter is always set to `\n` 6 | on cygwin 7 | - speed up 'goto session' prompt 8 | - fix creating new sessions with a '.' in the name 9 | 10 | ### v2.3.0, 2015-06-19 11 | - split 'goto session' script into 2 files, make it simpler 12 | - another 'goto session' feature refactoring 13 | - add 'kill session' key binding 14 | - refactor script names 15 | - reduce duplication by moving some functions to a shared file 16 | 17 | ### v2.2.0, 2015-01-29 18 | - bugfix: when a pane containing "vim" is promoted to a session, the moved pane 19 | has dimensions 80x25. This is the default `new-session -d` win size. Fixing 20 | this by first switching to a new session (so the window is resized), then 21 | pulling target pane over. 22 | - 'goto-session' feature - when session list does not fit on the screen, show it 23 | in columns 24 | - 'goto-session' - when all the sessions don't fit on the screen, the last 25 | displayed element is '...' indicating there's more sessions 26 | 27 | ### v2.1.0, 2015-01-11 28 | - add a `@` key binding for "promoting" current pane into a new session 29 | 30 | ### v2.0.1, 2014-11-21 31 | - fix bug, main script not working 32 | - change tmux option variables to have hyphens instead of underscores (tmux 33 | uses hyphens) 34 | - bugfix: when creating a new session, if there is a session 'ruby_foo', you 35 | can't create a session 'ruby'. Instead you would get switched to session 36 | 'ruby_foo'. 37 | - bugfix: creating a new session when using non-standard socket file. The 38 | command for creating new sessions now explicitly uses appropriate socket file. 39 | 40 | ### v2.0.0, 2014-08-03 41 | - plugin name change 42 | - revamp the readme 43 | - update the plugin main file and user variables 44 | 45 | ### v1.2.0, 2014-08-03 46 | - refactoring. Empty submission quits the 'goto loop' 47 | - simplify readme 48 | - add a `C` keybinding for creating new sessions 49 | - add a 'create new session' feature to readme 50 | 51 | ### v1.1.0, 2014-07-30 52 | - add other plugins list to the README 53 | - update readme to reflect github organization change 54 | - add alternate session key binding `prefix + S` 55 | 56 | ### v1.0.0, 2014-06-01 57 | 58 | - tag version 1.0.0 59 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Bruno Sutic 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included 11 | in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 19 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tmux sessionist 2 | 3 | Lightweight tmux utilities for manipulating tmux sessions. 4 | 5 | Tested and working on Linux, OSX and Cygwin. 6 | 7 | ### Problem(s) 8 | 9 | Sessions are a second class citizen in tmux environment: 10 | 11 | - there are no default key bindings for creating or deleting sessions 12 | - creating a session is cumbersome, just try `tmux new-session -s name` 13 | inside tmux (hint: you first have to detach) 14 | - deleting (killing) current session by default detaches tmux (why?) 15 | - no fast way for session switching when there's more than ~5 sessions 16 | 17 | This plugin solves the above problems. 18 | 19 | ### Features 20 | 21 | - `prefix + g` - prompts for session name and switches to it. Performs 'kind-of' 22 | name completion.
23 | Faster than the built-in `prefix + s` prompt for long session lists. 24 | - `prefix + C` (shift + c) - prompt for creating a new session by name. 25 | - `prefix + X` (shift + x) - kill current session without detaching tmux. 26 | - `prefix + S` (shift + s) - switches to the last session.
27 | The same as built-in `prefix + L` that everyone seems to override with 28 | some other binding. 29 | - `prefix + @` - promote current pane into a new session.
30 | Analogous to how `prefix + !` breaks current pane to a new window. 31 | - `prefix + ctrl-@` - promote current window into a new session. 32 | - `prefix + t` - join currently marked pane (`prefix + m`) to current session/window, and switch to it 33 | - secondary-keys 34 | - `h`, `-`, `"`: join horizontally 35 | - `v`, `|`, `%`: join vertically 36 | - `f`, `@`: join full screen 37 | 38 | ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) 39 | 40 | Add plugin to the list of TPM plugins in `.tmux.conf`: 41 | 42 | set -g @plugin 'tmux-plugins/tmux-sessionist' 43 | 44 | Hit `prefix + I` to fetch the plugin and source it. You can now use the plugin. 45 | 46 | ### Manual Installation 47 | 48 | Clone the repo: 49 | 50 | $ git clone https://github.com/tmux-plugins/tmux-sessionist ~/clone/path 51 | 52 | Add this line to the bottom of `.tmux.conf`: 53 | 54 | run-shell ~/clone/path/sessionist.tmux 55 | 56 | Reload TMUX environment with `$ tmux source-file ~/.tmux.conf`. You can now use 57 | the plugin. 58 | 59 | ### Other plugins 60 | 61 | You might also find these useful: 62 | 63 | - [pain control](https://github.com/tmux-plugins/tmux-pain-control) - useful standard 64 | bindings for controlling panes 65 | - [logging](https://github.com/tmux-plugins/tmux-logging) - easy logging and 66 | screen capturing 67 | 68 | ### License 69 | 70 | [MIT](LICENSE.md) 71 | -------------------------------------------------------------------------------- /screenshots/gif_source.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-sessionist/a315c423328d9bdf5cf796435ce7075fa5e1bffb/screenshots/gif_source.pdf -------------------------------------------------------------------------------- /screenshots/sessions_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-sessionist/a315c423328d9bdf5cf796435ce7075fa5e1bffb/screenshots/sessions_list.png -------------------------------------------------------------------------------- /screenshots/tmux_goto_session.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmux-plugins/tmux-sessionist/a315c423328d9bdf5cf796435ce7075fa5e1bffb/screenshots/tmux_goto_session.gif -------------------------------------------------------------------------------- /scripts/goto_session.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | main() { 6 | # displays tmux session list 7 | tmux run-shell -b "$CURRENT_DIR/list_sessions.sh" 8 | # goto command prompt 9 | tmux command -p session: "run '$CURRENT_DIR/switch_or_loop.sh \"%1\"'" 10 | } 11 | main 12 | -------------------------------------------------------------------------------- /scripts/helpers.sh: -------------------------------------------------------------------------------- 1 | # tmux show-option "q" (quiet) flag does not set return value to 1, even though 2 | # the option does not exist. This function patches that. 3 | get_tmux_option() { 4 | local option=$1 5 | local default_value=$2 6 | local option_value=$(tmux show-option -gqv "$option") 7 | if [ -z "$option_value" ]; then 8 | echo "$default_value" 9 | else 10 | echo "$option_value" 11 | fi 12 | } 13 | 14 | # Ensures a message is displayed for 5 seconds in tmux prompt. 15 | # Does not override the 'display-time' tmux option. 16 | display_message() { 17 | local message="$1" 18 | 19 | # display_duration defaults to 5 seconds, if not passed as an argument 20 | if [ "$#" -eq 2 ]; then 21 | local display_duration="$2" 22 | else 23 | local display_duration="5000" 24 | fi 25 | 26 | # saves user-set 'display-time' option 27 | local saved_display_time=$(get_tmux_option "display-time" "750") 28 | 29 | # sets message display time to 5 seconds 30 | tmux set-option -gq display-time "$display_duration" 31 | 32 | # displays message 33 | tmux display-message "$message" 34 | 35 | # restores original 'display-time' value 36 | tmux set-option -gq display-time "$saved_display_time" 37 | } 38 | 39 | tmux_socket() { 40 | echo $TMUX | cut -d',' -f1 41 | } 42 | 43 | session_exists_exact() { 44 | tmux has-session -t "=${SESSION_NAME}" >/dev/null 2>&1 45 | } 46 | 47 | session_exists_prefix() { 48 | tmux has-session -t "$SESSION_NAME" >/dev/null 2>&1 49 | } 50 | 51 | switch_to_session() { 52 | local session_name="$1" 53 | tmux switch-client -t "$session_name" 54 | } 55 | -------------------------------------------------------------------------------- /scripts/join_pane.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | # where the secondary key bindings are bound 6 | SECONDARY_KEY_TABLE="$1" 7 | # sentinel for the full screen join that's also safe to pass to `join-pane` 8 | BREAK_PANE_FLAG="$2" 9 | # passed to script on the 2-key binding invocation 10 | JOIN_PANE_FLAG="$3" 11 | 12 | source "$CURRENT_DIR/helpers.sh" 13 | 14 | join_pane() { 15 | local join_pane_flag="$1" 16 | tmux join-pane "$join_pane_flag" || \ 17 | tmux display-message "Mark a(nother) pane first" 18 | 19 | if [ "$BREAK_PANE_FLAG" == "$join_pane_flag" ]; then 20 | tmux break-pane || true 21 | fi 22 | } 23 | 24 | main() { 25 | if [ -z "$JOIN_PANE_FLAG"]; then 26 | tmux switch-client -T"$SECONDARY_KEY_TABLE" 27 | else 28 | join_pane "$JOIN_PANE_FLAG" 29 | fi 30 | } 31 | main 32 | -------------------------------------------------------------------------------- /scripts/kill_session.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | source "$CURRENT_DIR/helpers.sh" 6 | 7 | # global vars passed to the script as arguments 8 | CURRENT_SESSION_ID="$1" 9 | 10 | switch_to_next_session() { 11 | tmux switch-client -n 12 | } 13 | 14 | switch_to_alternate_session() { 15 | tmux switch-client -l 16 | } 17 | 18 | alternate_session_name() { 19 | tmux display -p "#{client_last_session}" 20 | } 21 | 22 | current_session_name() { 23 | tmux display -p "#{client_session}" 24 | } 25 | 26 | number_of_sessions() { 27 | tmux list-sessions | 28 | wc -l | 29 | sed "s/ //g" 30 | } 31 | 32 | # Setting `detach-on-destroy off` will also switch session, but it does not 33 | # respect alternate session. 34 | switch_session() { 35 | local alternate_session_name="$(alternate_session_name)" 36 | if [ "$(number_of_sessions)" -eq 1 ]; then 37 | # this is the only session, do nothing and wait for tmux server death 38 | return 0 39 | elif [ -z "$alternate_session_name" ]; then 40 | # alternate session does not exist 41 | switch_to_next_session 42 | elif [ "$alternate_session_name" == "$(current_session_name)" ]; then 43 | # current session IS alternate session 44 | switch_to_next_session 45 | else 46 | switch_to_alternate_session 47 | fi 48 | } 49 | 50 | kill_current_session() { 51 | tmux kill-session -t "$CURRENT_SESSION_ID" 52 | } 53 | 54 | main() { 55 | switch_session 56 | kill_current_session 57 | } 58 | main 59 | -------------------------------------------------------------------------------- /scripts/kill_session_prompt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | # global vars passed to the script as arguments 6 | CURRENT_SESSION_NAME="$1" 7 | CURRENT_SESSION_ID="$2" 8 | 9 | main() { 10 | tmux confirm -p "kill-session ${CURRENT_SESSION_NAME}? (y/n)" "run '$CURRENT_DIR/kill_session.sh \'$CURRENT_SESSION_ID''" 11 | } 12 | main 13 | -------------------------------------------------------------------------------- /scripts/list_sessions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | session_list() { 4 | tmux list-sessions -F "#{session_name}" 5 | } 6 | 7 | output_height() { 8 | local list="$1" 9 | echo "$list" | 10 | wc -l | 11 | tr -d ' ' 12 | } 13 | 14 | # calculates required number of columns for the multi-column output 15 | get_column_number() { 16 | local output_height="$1" 17 | local pane_height="$2" 18 | local columns="$(expr $output_height / $pane_height )" 19 | if [ $(expr $output_height % $pane_height ) -gt 0 ]; then 20 | columns=$(expr $columns + 1) 21 | fi 22 | echo "$columns" 23 | } 24 | 25 | get_column_width() { 26 | declare -a array=("${!1}") 27 | local width=0 28 | # searching for the longest session name 29 | for session_name in "${array[@]}"; do 30 | if [ ${#session_name} -gt $width ]; then 31 | width="${#session_name}" 32 | fi 33 | done 34 | # add some padding to the right 35 | echo $((width + 2)) 36 | } 37 | 38 | print_multi_column_output() { 39 | local output_height="$1" 40 | local pane_height="$2" 41 | local pane_width="$3" 42 | local columns="$(get_column_number "$output_height" "$pane_height")" 43 | eval session_array=( $(tmux list-sessions -F "'#{session_name}'") ) 44 | local width="$(get_column_width session_array[@])" 45 | 46 | # limit number of displayed columns 47 | local max_columns=$(( $((pane_width + 2)) / $width)) 48 | if [ $columns -gt $max_columns ]; then 49 | # there's more columns than it fits on the display 50 | columns="$max_columns" 51 | # last displayed element indicates there's more 52 | session_array[$((pane_height * columns - 1))]="..." 53 | fi 54 | 55 | # Composing a string that prints variable number of columns. 56 | # Example print_string for 2 columns: 57 | # printf "%-17s %s\n" "${session_array[$index]}" "${session_array[$((index + 54 ))]}" 58 | local first_arg='' 59 | local arg_list='' 60 | local i=1 61 | while [ $i -lt $columns ]; do 62 | first_arg+="%-${width}s" 63 | arg_list+=" \"\${session_array[\$((index + $((i * $pane_height)) ))]}\"" 64 | i=$((i + 1)) 65 | done 66 | 67 | local print_string='' 68 | print_string+='printf "' 69 | print_string+=$first_arg 70 | print_string+='%s\n" "${session_array[$index]}"' 71 | print_string+=$arg_list 72 | 73 | local index=0 74 | while [ $index -lt $pane_height ]; do 75 | eval "$print_string" 76 | index=$((index + 1)) 77 | done 78 | } 79 | 80 | main() { 81 | local pane_height=$(tmux display-message -p -F "#{pane_height}") 82 | local pane_width=$(tmux display-message -p -F "#{pane_width}") 83 | local session_list="$(session_list)" 84 | local output_height=$(output_height "$session_list") 85 | if [ $output_height -gt $pane_height ]; then 86 | print_multi_column_output "$output_height" "$pane_height" "$pane_width" 87 | else 88 | echo "$session_list" 89 | fi 90 | } 91 | main 92 | -------------------------------------------------------------------------------- /scripts/new_session.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | # global variable 6 | SESSION_NAME="$1" 7 | 8 | source "$CURRENT_DIR/helpers.sh" 9 | 10 | session_name_not_provided() { 11 | [ -z "$SESSION_NAME" ] 12 | } 13 | 14 | create_new_tmux_session() { 15 | if session_name_not_provided; then 16 | exit 0 17 | elif session_exists_exact; then 18 | switch_to_session "$SESSION_NAME" 19 | display_message "Switched to existing session ${SESSION_NAME}" "2000" 20 | else 21 | # New session name may differ from the input. Eg input name may be 22 | # '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" 28 | fi 29 | } 30 | 31 | main() { 32 | create_new_tmux_session 33 | } 34 | main 35 | -------------------------------------------------------------------------------- /scripts/new_session_prompt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | main() { 6 | tmux command -p "new session name:" "run '$CURRENT_DIR/new_session.sh \"%1\"'" 7 | } 8 | main 9 | -------------------------------------------------------------------------------- /scripts/promote_pane.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | source "$CURRENT_DIR/helpers.sh" 6 | 7 | # global vars passed to the script as arguments 8 | CURRENT_SESSION_NAME="$1" 9 | CURRENT_PANE_ID="$2" 10 | PANE_CURRENT_PATH="$3" 11 | 12 | number_of_panes() { 13 | tmux list-panes -s -t "$CURRENT_SESSION_NAME" | 14 | wc -l | 15 | tr -d ' ' 16 | } 17 | 18 | create_new_session() { 19 | TMUX="" tmux -S "$(tmux_socket)" new-session -c "$PANE_CURRENT_PATH" -d -P -F "#{session_name}" 20 | } 21 | 22 | new_session_pane_id() { 23 | local session_name="$1" 24 | tmux list-panes -t "$session_name" -F "#{pane_id}" 25 | } 26 | 27 | promote_pane() { 28 | local session_name="$(create_new_session)" 29 | local new_session_pane_id="$(new_session_pane_id "$session_name")" 30 | tmux join-pane -s "$CURRENT_PANE_ID" -t "$new_session_pane_id" 31 | tmux kill-pane -t "$new_session_pane_id" 32 | switch_to_session "$session_name" 33 | } 34 | 35 | main() { 36 | if [ "$(number_of_panes)" -gt 1 ]; then 37 | promote_pane 38 | else 39 | display_message "Can't promote with only one pane in session" 40 | fi 41 | } 42 | main 43 | -------------------------------------------------------------------------------- /scripts/promote_window.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | source "$CURRENT_DIR/helpers.sh" 6 | 7 | # global vars passed to the script as arguments 8 | CURRENT_SESSION_NAME="$1" 9 | CURRENT_WINDOW_ID="$2" 10 | CURRENT_WINDOW_NAME="$3" 11 | WINDOW_CURRENT_PATH="$4" 12 | 13 | number_of_windows() { 14 | tmux list-windows -t "$CURRENT_SESSION_NAME" | 15 | wc -l | 16 | tr -d ' ' 17 | } 18 | 19 | create_new_session() { 20 | TMUX="" tmux -S "$(tmux_socket)" new-session -c "$WINDOW_CURRENT_PATH" -s "$CURRENT_WINDOW_NAME" -d -P -F "#{session_name}" 21 | } 22 | 23 | new_session_window_id() { 24 | local session_name="$1" 25 | tmux list-windows -t "$session_name" -F "#{window_id}" 26 | } 27 | 28 | promote_window() { 29 | local session_name="$(create_new_session)" 30 | local new_session_window_id="$(new_session_window_id "$session_name")" 31 | tmux swap-window -s "$CURRENT_WINDOW_ID" -t "$new_session_window_id" 32 | tmux kill-window -t "$new_session_window_id" 33 | switch_to_session "$session_name" 34 | } 35 | 36 | main() { 37 | if [ "$(number_of_windows)" -gt 1 ]; then 38 | promote_window 39 | else 40 | display_message "Can't promote with only one window in session" 41 | fi 42 | } 43 | main 44 | -------------------------------------------------------------------------------- /scripts/switch_or_loop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | SESSION_NAME="$1" 6 | 7 | source "$CURRENT_DIR/helpers.sh" 8 | 9 | dismiss_session_list_page_from_view() { 10 | tmux send-keys C-c 11 | } 12 | 13 | session_name_not_provided() { 14 | [ -z "$SESSION_NAME" ] 15 | } 16 | 17 | main() { 18 | if session_name_not_provided; then 19 | dismiss_session_list_page_from_view 20 | exit 0 21 | fi 22 | if session_exists_prefix; then 23 | dismiss_session_list_page_from_view 24 | tmux switch-client -t "$SESSION_NAME" 25 | else 26 | # goto command prompt again 27 | tmux command -p session: "run '$CURRENT_DIR/switch_or_loop.sh \"%1\"'" 28 | fi 29 | } 30 | main 31 | -------------------------------------------------------------------------------- /sessionist.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | default_key_bindings_goto="g" 6 | tmux_option_goto="@sessionist-goto" 7 | 8 | default_key_bindings_alternate="S" 9 | tmux_option_alternate="@sessionist-alternate" 10 | 11 | default_key_bindings_new="C" 12 | tmux_option_new="@sessionist-new" 13 | 14 | default_key_bindings_promote_pane="@" 15 | tmux_option_promote_pane="@sessionist-promote-pane" 16 | 17 | default_key_bindings_promote_window="C-@" 18 | tmux_option_promote_window="@sessionist-promote-window" 19 | 20 | default_key_bindings_join_pane="t" 21 | tmux_option_join_pane="@sessionist-join-pane" 22 | 23 | default_key_bindings_kill_session="X" 24 | tmux_option_kill_session="@sessionist-kill-session" 25 | 26 | source "$CURRENT_DIR/scripts/helpers.sh" 27 | 28 | # Multiple bindings can be set. Default binding is "g". 29 | set_goto_session_bindings() { 30 | local key_bindings=$(get_tmux_option "$tmux_option_goto" "$default_key_bindings_goto") 31 | local key 32 | for key in $key_bindings; do 33 | tmux bind "$key" run "$CURRENT_DIR/scripts/goto_session.sh" 34 | done 35 | } 36 | 37 | set_alternate_session_binding() { 38 | local key_bindings=$(get_tmux_option "$tmux_option_alternate" "$default_key_bindings_alternate") 39 | local key 40 | for key in $key_bindings; do 41 | # switch to the last/alternate session 42 | tmux bind "$key" switch-client -l 43 | done 44 | } 45 | 46 | # Prompt for creating a new session. If the session with the same name exists, 47 | # it will switch to existing session. 48 | set_new_session_binding() { 49 | local key_bindings=$(get_tmux_option "$tmux_option_new" "$default_key_bindings_new") 50 | local key 51 | for key in $key_bindings; do 52 | tmux bind "$key" run "$CURRENT_DIR/scripts/new_session_prompt.sh" 53 | done 54 | } 55 | 56 | # "Promote" the current pane to a new session 57 | set_promote_pane_binding() { 58 | local key_bindings=$(get_tmux_option "$tmux_option_promote_pane" "$default_key_bindings_promote_pane") 59 | local key 60 | for key in $key_bindings; do 61 | tmux bind "$key" run "$CURRENT_DIR/scripts/promote_pane.sh '#{session_name}' '#{pane_id}' '#{pane_current_path}'" 62 | done 63 | } 64 | 65 | # "Promote" the current window to a new session 66 | set_promote_window_binding() { 67 | local key_bindings=$(get_tmux_option "$tmux_option_promote_window" "$default_key_bindings_promote_window") 68 | local key 69 | for key in $key_bindings; do 70 | tmux bind "$key" run "$CURRENT_DIR/scripts/promote_window.sh '#{session_name}' '#{window_id}' '#{window_name}' '#{pane_current_path}'" 71 | done 72 | } 73 | 74 | set_join_pane_secondary_bindings() { 75 | local secondary_key_table="$1" 76 | local break_pane_flag="$2" 77 | 78 | while read -r key flag; do 79 | tmux bind-key -T"$secondary_key_table" "$key" run \ 80 | "'$CURRENT_DIR/scripts/join_pane.sh' '$secondary_key_table' '$break_pane_flag' '$flag'" 81 | done <