-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_pane.tmux
executable file
·47 lines (41 loc) · 1.82 KB
/
select_pane.tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Default values
default_bind_key='s'
default_preview_pane='true'
default_fzf_window_position='center,70%,80%'
default_fzf_preview_window_position='right,,,nowrap'
default_tmux_list_panes_format='session_name window_name pane_title pane_current_command'
# User overridable options
tmux_bind_key="@fzf_pane_switch_bind-key"
tmux_preview_pane="@fzf_pane_switch_preview-pane"
tmux_fzf_window_position="@fzf_pane_switch_window-position"
tmux_fzf_preview_window_position="@fzf_pane_switch_preview-pane-position"
tmux_list_panes_format="@fzf_pane_switch_list-panes-format"
# Function to get variables from tmux
get_tmux_option() {
local option=$1
local default_value=$2
local option_override
option_override=$(tmux show-option -gqv "${option}")
if [ -z "${option_override}" ]; then
echo "${default_value}"
else
echo "${option_override}"
fi
}
# Function to set the key binding
function set_switch_pane_bindings {
local bind_key
bind_key=$(get_tmux_option "${tmux_bind_key}" "${default_bind_key}")
local preview_pane
preview_pane=$(get_tmux_option "${tmux_preview_pane}" "${default_preview_pane}")
local fzf_window_position
fzf_window_position=$(get_tmux_option "${tmux_fzf_window_position}" "${default_fzf_window_position}")
local fzf_preview_window_position
fzf_preview_window_position=$(get_tmux_option "${tmux_fzf_preview_window_position}" "${default_fzf_preview_window_position}")
local list_panes_format
list_panes_format=$(get_tmux_option "${tmux_list_panes_format}" "${default_tmux_list_panes_format}")
tmux bind-key "${bind_key}" run-shell "${CURRENT_DIR}/select_pane.sh ${preview_pane} ${fzf_window_position} ${fzf_preview_window_position} '${list_panes_format}'"
}
set_switch_pane_bindings