summaryrefslogtreecommitdiff
path: root/ar/.local/bin/restartnvim
blob: 74d57c350c25dee18d8c77befcbc59a8f2b90afd (plain)
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
#!/bin/sh

set -e

# Set new line and tab for word splitting
IFS="
	"

# Check if the script is running inside a tmux session
if [ -z "$TMUX" ]; then
  echo "This script must be run from inside a tmux session."
  exit 1
fi

# Get the current tmux pane ID
TMUX_PANE=$(tmux display-message -p '#D')

# Send Escape, :wq, and Enter to Neovim in the tmux pane
tmux send-keys -t "$TMUX_PANE" Escape C-m ':wq' C-m

# Wait to ensure Neovim exits
sleep 0.5

# Detach the script from Neovim and wait a bit to ensure Neovim exits
(nohup sh -c "sleep 0.5; tmux send-keys -t \"$TMUX_PANE\" 'nvim -c \"execute \\\"edit \\\" . v:oldfiles[0] | normal '\''0\"' C-m" >/dev/null 2>&1 &)