-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvux
More file actions
executable file
·93 lines (77 loc) · 2.49 KB
/
Copy pathnvux
File metadata and controls
executable file
·93 lines (77 loc) · 2.49 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
show_help() {
cat << EOF
nvux - Open files in existing neovim instance within tmux
USAGE:
nvux [OPTIONS] [FILE] [+LINE]
OPTIONS:
-h, --help Show this help message and exit
ARGUMENTS:
FILE Path to file to open (optional)
+LINE Line number to jump to after opening file (optional)
Must be preceded by '+' (e.g., +42)
DESCRIPTION:
nvux opens files in an existing Neovim instance running
within a tmux session. It searches for active Neovim processes in the
current tmux session and opens the specified file in that instance.
If no existing Neovim instance is found, nvux will create one in a new pane.
When not running within a tmux session, nvux falls back to launching
regular Neovim.
EXAMPLES:
nvux # Open nvim in existing tmux instance
nvux file.txt # Open file.txt
nvux file.txt +25 # Open file.txt and jump to line 25
nvux /path/to/script.sh +1 # Open script.sh and jump to first line
EOF
}
# Parse options
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-*)
echo "Unknown option: $1" >&2
echo "Use -h for help" >&2
exit 1
;;
*)
break
;;
esac
shift
done
FILE="$1"
LINE="$2"
# Fallback to regular nvim if no tmux
if ! tmux info &>/dev/null; then
exec nvim "$@"
exit
fi
# Get current tmux session
SESSION=$(tmux display-message -p '#S')
# Find panes running nvim across ALL sessions and windows
NVIM_INFO=$(tmux list-panes -s -F '#{session_name}:#{window_index}.#{pane_index} #{pane_current_command}' | grep nvim | head -1)
if [ -n "$NVIM_INFO" ]; then
# Extract the session:window.pane part
NVIM_TARGET=$(echo "$NVIM_INFO" | cut -d' ' -f1)
# Switch to the session and window containing nvim
tmux switch-client -t "$NVIM_TARGET"
tmux select-pane -t "$NVIM_TARGET"
# Sends an escape in case the user is in insert mode.
tmux send-keys -t "$NVIM_TARGET" Escape
# Open file in existing nvim
if [ -n "$LINE" ]; then
tmux send-keys -t "$NVIM_TARGET" ":e $FILE | $LINE" Enter
else
tmux send-keys -t "$NVIM_TARGET" ":e $FILE" Enter
fi
else
# Create new pane with nvim in current session
if [ -n "$FILE" ]; then
tmux new-window -c "$(pwd)" "nvim $*"
else
tmux new-window -c "$(pwd)" "nvim"
fi
fi