@@ -4,18 +4,18 @@ shopt -s globstar
4
4
get_tmux_option () {
5
5
local option=" $1 "
6
6
local default_value=" $2 "
7
- local option_value=$( tmux show-option -gqv " $option " )
7
+ local option_value=$( tmux show-option -gqv " @ $option " )
8
8
if [ -z " $option_value " ]; then
9
9
echo " $default_value "
10
10
else
11
11
echo " $option_value "
12
12
fi
13
13
}
14
14
15
- OPEN_STRATEGY=" $( get_tmux_option " $open_strategy " " :e" ) "
16
- MENU_STYLE=" $( get_tmux_option " $menu_style " ) "
17
- MENU_SELECTED_STYLE=" $( get_tmux_option " $menu_selected_style " ) "
18
- PRIORITIZE_WINDOW=" $( get_tmux_option " $prioritize_window " ) "
15
+ OPEN_STRATEGY=" $( get_tmux_option " open-strategy " " :e" ) "
16
+ MENU_STYLE=" $( get_tmux_option " menu-style " " " ) "
17
+ MENU_SELECTED_STYLE=" $( get_tmux_option " menu-selected-style " ) "
18
+ PRIORITIZE_WINDOW=" $( get_tmux_option " ton-prioritize-window " ) "
19
19
20
20
if [ -n " $MENU_STYLE " ]; then
21
21
tmux_menu_s=" -s $MENU_STYLE "
@@ -44,13 +44,14 @@ LINE=${a[1]:-0}
44
44
COLUMN=${a[2]:- 0}
45
45
46
46
# Get all nvim listening sockets (default location)
47
- # TODO: don't use `ls` here. Maybe ` find` instead
47
+ # TODO: don't use $(ls) here. Maybe $( find) instead
48
48
readarray -t LISTEN_SOCKS < <( ls " ${XDG_RUNTIME_DIR:- ${TMPDIR} nvim.${USER} } " /** /nvim.* .0 2> /dev/null)
49
49
50
50
CURRENT_WINDOW_INDEX=$( tmux display-message -p ' #{window_index}' )
51
51
CURRENT_SESSION_NAME=$( tmux display-message -p ' #{session_name}' )
52
52
53
53
MENU_ARGS=()
54
+ MENU_CHOICES=0
54
55
SOCK_COUNT=${# LISTEN_SOCKS[@]}
55
56
SOCK_INDEX=1
56
57
for sock in " ${LISTEN_SOCKS[@]} " ; do
@@ -71,28 +72,34 @@ for sock in "${LISTEN_SOCKS[@]}"; do
71
72
window_index=${ids[0]}
72
73
window_name=${ids[1]}
73
74
pane_index=${ids[2]}
74
- session_name=${ids[3]}
75
+ session_name=${ids[3]// [$'\r\n'] / }
75
76
76
- [ " $CURRENT_SESSION_NAME " != " $session_name " ] || continue
77
+ if [[ " $CURRENT_SESSION_NAME " != " $session_name " ]]; then
78
+ continue
79
+ fi
77
80
78
81
c1=" nvim --server $sock --remote-send \" <esc>$OPEN_STRATEGY $FILE <cr>\" "
79
82
c2=" nvim --server $sock --remote-send \" <esc>:call cursor($LINE , $COLUMN )<cr>\" "
80
- c3=" tmux selectw -t $window_index && tmux selectp -t $pane_index "
83
+ c3=" tmux selectw -t $session_name : $ window_index && tmux selectp -t $pane_index "
81
84
remote_open=" $c1 && $c2 && $c3 "
85
+ echo " wincount: $SESSION_WINDOW_COUNT , $PRIORITIZE_WINDOW , $window_index , $CURRENT_WINDOW_INDEX "
82
86
if [[ $SOCK_COUNT == 1 || ($window_index == " $CURRENT_WINDOW_INDEX " && $PRIORITIZE_WINDOW == true) ]]; then
83
87
# we found the only nvim, or found the first one in our window when prioritizing current window
84
88
eval " $remote_open "
85
89
exit 0
86
90
else
87
91
# store this nvim instance for selection
92
+ MENU_CHOICES=$(( MENU_CHOICES + 1 ))
88
93
MENU_ARGS+=(" [$window_index $window_name ]: pane $pane_index " " $SOCK_INDEX " " run '$remote_open '" )
89
94
fi
90
95
SOCK_INDEX=$(( SOCK_INDEX + 1 ))
91
96
done
92
97
93
- if [[ ${MENU_ARGS[0]} ]]; then
98
+ if [[ $MENU_CHOICES == 1 ]]; then
99
+ eval " $( echo " ${MENU_ARGS[2]# ' run ' } " | tr -d " '" ) "
100
+ elif [[ $MENU_CHOICES -gt 1 ]]; then
101
+ echo " ${MENU_ARGS[@]} "
94
102
# open menu for selection
95
- echo " $tmux_menu_s $tmux_menu_H "
96
103
# shellcheck disable=SC2086
97
104
tmux menu $tmux_menu_s $tmux_menu_H -T " tmux-open-nvim: $FILE " " ${MENU_ARGS[@]} "
98
105
else
0 commit comments