Skip to content

Commit 34da7ca

Browse files
committed
fix: symlink to ton not working
Fixed the issue where a symlink to the ton script doesn't work since it required other scripts. Consolidated everything into the ton script. Removed attempt to automatically add ton to PATH since it isn't a fully working solution. The symlink works better. Relates to #6
1 parent 3474ff7 commit 34da7ca

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

scripts/helpers.sh

-10
This file was deleted.

scripts/ton

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env bash
22
shopt -s globstar
33

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+
}
814

915
OPEN_STRATEGY="$(get_tmux_option "$open_strategy" ":e")"
1016
MENU_STYLE="$(get_tmux_option "$menu_style")"
@@ -38,33 +44,36 @@ LINE=${a[1]:-0}
3844
COLUMN=${a[2]:-0}
3945

4046
# Get all nvim listening sockets (default location)
47+
# TODO: don't use `ls` here. Maybe `find` instead
4148
readarray -t LISTEN_SOCKS < <(ls "${XDG_RUNTIME_DIR:-${TMPDIR}nvim.${USER}}"/**/nvim.*.0 2>/dev/null)
4249

4350
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}')
4552

4653
MENU_ARGS=()
4754
SOCK_COUNT=${#LISTEN_SOCKS[@]}
4855
SOCK_INDEX=1
4956
for sock in "${LISTEN_SOCKS[@]}"; do
5057
# extract pid from socket path
5158
server_pid=$(echo "$sock" | awk -F'.' '{print $(NF-1)}')
59+
[ -n "$server_pid" ] || continue
60+
5261
# process id of server's parent, which is the nvim client
5362
client_pid=$(ps -o ppid= -p "$server_pid" | tr -d ' ')
63+
[ -n "$client_pid" ] || continue
64+
5465
# process id of tmux pane that contains the nvim client
5566
pane_pid=$(ps -o ppid= -p "$client_pid" | tr -d ' ')
67+
[ -n "$pane_pid" ] || continue
5668

5769
# 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}")
5971
window_index=${ids[0]}
6072
window_name=${ids[1]}
6173
pane_index=${ids[2]}
62-
session_id=${ids[3]}
74+
session_name=${ids[3]}
6375

64-
# shellcheck disable=SC2086
65-
if [ $CURRENT_SESSION_ID != $session_id ]; then
66-
continue
67-
fi
76+
[ "$CURRENT_SESSION_NAME" != "$session_name" ] || continue
6877

6978
c1="nvim --server $sock --remote-send \"<esc>$OPEN_STRATEGY $FILE<cr>\""
7079
c2="nvim --server $sock --remote-send \"<esc>:call cursor($LINE, $COLUMN)<cr>\""

tmux_open_nvim.tmux

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4-
SCRIPT_DIR="$CURRENT_DIR/scripts"
5-
6-
source "$CURRENT_DIR/scripts/helpers.sh"
7-
8-
path_add() {
9-
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
10-
NEW_PATH="${PATH:+"$PATH:"}$1"
11-
tmux set-environment -g PATH "$NEW_PATH"
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"
1211
fi
1312
}
1413

@@ -37,6 +36,5 @@ main() {
3736
set_menu_style
3837
set_menu_selected_style
3938
set_prioritize_window
40-
path_add "$SCRIPT_DIR"
4139
}
4240
main

0 commit comments

Comments
 (0)