|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | shopt -s globstar
|
3 | 3 |
|
4 |
| -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
5 |
| - |
6 |
| -source "$CURRENT_DIR/variables.sh" |
7 |
| -source "$CURRENT_DIR/helpers.sh" |
| 4 | +get_tmux_option() { |
| 5 | + local option="$1" |
| 6 | + local default_value="$2" |
| 7 | + local option_value=$(tmux show-option -gqv "$option") |
| 8 | + if [ -z "$option_value" ]; then |
| 9 | + echo "$default_value" |
| 10 | + else |
| 11 | + echo "$option_value" |
| 12 | + fi |
| 13 | +} |
8 | 14 |
|
9 | 15 | OPEN_STRATEGY="$(get_tmux_option "$open_strategy" ":e")"
|
10 | 16 | MENU_STYLE="$(get_tmux_option "$menu_style")"
|
@@ -38,33 +44,36 @@ LINE=${a[1]:-0}
|
38 | 44 | COLUMN=${a[2]:-0}
|
39 | 45 |
|
40 | 46 | # Get all nvim listening sockets (default location)
|
| 47 | +# TODO: don't use `ls` here. Maybe `find` instead |
41 | 48 | readarray -t LISTEN_SOCKS < <(ls "${XDG_RUNTIME_DIR:-${TMPDIR}nvim.${USER}}"/**/nvim.*.0 2>/dev/null)
|
42 | 49 |
|
43 | 50 | CURRENT_WINDOW_INDEX=$(tmux display-message -p '#{window_index}')
|
44 |
| -CURRENT_SESSION_ID=$(tmux display-message -p '#{session_id}') |
| 51 | +CURRENT_SESSION_NAME=$(tmux display-message -p '#{session_name}') |
45 | 52 |
|
46 | 53 | MENU_ARGS=()
|
47 | 54 | SOCK_COUNT=${#LISTEN_SOCKS[@]}
|
48 | 55 | SOCK_INDEX=1
|
49 | 56 | for sock in "${LISTEN_SOCKS[@]}"; do
|
50 | 57 | # extract pid from socket path
|
51 | 58 | server_pid=$(echo "$sock" | awk -F'.' '{print $(NF-1)}')
|
| 59 | + [ -n "$server_pid" ] || continue |
| 60 | + |
52 | 61 | # process id of server's parent, which is the nvim client
|
53 | 62 | client_pid=$(ps -o ppid= -p "$server_pid" | tr -d ' ')
|
| 63 | + [ -n "$client_pid" ] || continue |
| 64 | + |
54 | 65 | # process id of tmux pane that contains the nvim client
|
55 | 66 | pane_pid=$(ps -o ppid= -p "$client_pid" | tr -d ' ')
|
| 67 | + [ -n "$pane_pid" ] || continue |
56 | 68 |
|
57 | 69 | # tmux ids for the nvim client pane
|
58 |
| - readarray -d ' ' -t ids < <(tmux list-panes -a -f "#{==:#{pane_pid},$pane_pid}" -F "#{window_index} #{window_name} #{pane_index} #{session_id}") |
| 70 | + readarray -d ' ' -t ids < <(tmux list-panes -a -f "#{==:#{pane_pid},$pane_pid}" -F "#{window_index} #{window_name} #{pane_index} #{session_name}") |
59 | 71 | window_index=${ids[0]}
|
60 | 72 | window_name=${ids[1]}
|
61 | 73 | pane_index=${ids[2]}
|
62 |
| - session_id=${ids[3]} |
| 74 | + session_name=${ids[3]} |
63 | 75 |
|
64 |
| - # shellcheck disable=SC2086 |
65 |
| - if [ $CURRENT_SESSION_ID != $session_id ]; then |
66 |
| - continue |
67 |
| - fi |
| 76 | + [ "$CURRENT_SESSION_NAME" != "$session_name" ] || continue |
68 | 77 |
|
69 | 78 | c1="nvim --server $sock --remote-send \"<esc>$OPEN_STRATEGY $FILE<cr>\""
|
70 | 79 | c2="nvim --server $sock --remote-send \"<esc>:call cursor($LINE, $COLUMN)<cr>\""
|
|
0 commit comments