-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_nvim_running_in_current_tmux_session
executable file
·44 lines (35 loc) · 1.26 KB
/
is_nvim_running_in_current_tmux_session
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
#!/bin/zsh
is_nvim_running_in_current_tmux_session() {
# Check if we're currently in a tmux session
if [ -z "$TMUX" ]; then
echo "false"
exit 1
fi
# Get the current tmux session name
SESSION_NAME=$(tmux display-message -p '#S')
# echo "session name: $SESSION_NAME"
# Get the current window name
WINDOW_NAME=$(tmux display-message -p '#W')
# echo "window name: $WINDOW_NAME"
# Initialize a variable to track if nvim is running
nvim_running=false
# Iterate over all pane IDs in the current tmux session
for pane in $(tmux list-panes -s -t "$SESSION_NAME" -F "#{pane_id}"); do
# Get the command being run in the current pane
pane_command=$(tmux display-message -p -t "$pane" "#{pane_current_command}")
# Check if the current command is 'nvim'
if [[ "$pane_command" == "nvim" ]]; then
nvim_running=true
nvim_pid=$(ps -o pid,tty,command | grep "[n]vim" | grep "$(basename $(tmux display-message -p -t "%10" "#{pane_tty}"))" | awk '{print $1}')
break
fi
done
# Output the result based on whether nvim was found
if $nvim_running; then
echo $nvim_pid
exit 0
else
# echo "false"
exit 1
fi
}