-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvim-lookup
More file actions
executable file
·44 lines (37 loc) · 1.07 KB
/
vim-lookup
File metadata and controls
executable file
·44 lines (37 loc) · 1.07 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
#!/bin/bash
VIM=nvim
if [ "$#" -lt 1 ]; then
exec $VIM
exit 0
fi
SOURCEFILE=$(basename "$@")
echo $SOURCEFILE
VIMRC="set backupdir=~/.vim-tmp,/var/tmp,/tmp\nset directory=~/.vim-tmp,/var/tmp,/tmp\n"
ex --noplugin -u <(echo $VIMRC) -c "q" "$@"
if [ $? -ne 0 ] \
&& command -v tmux >/dev/null 2>&1 \
&& command -v fuser >/dev/null 2>&1 \
&& tmux list-sessions >/dev/null
then
echo $@ "is already open."
FNAME=`find ~/.vim-tmp /var/tmp /tmp -name "$SOURCEFILE.swp" -uid $UID 2>/dev/null`
PID=`fuser $FNAME 2>/dev/null | awk '{print $1}'`
TTY=`ps -o tty= -p $PID`
PANE=`tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index} #{pane_tty}' \
| egrep "$TTY" \
| awk '{print $1}'`
WINDOW=${PANE%.*}
if [ -n "$PANE" ]
then
tmux select-window -t $WINDOW
tmux select-pane -t $PANE
#echo $PID $TTY $PANE $WINDOW
else
echo $@ "not running in tmux."
echo "Opening..." $SOURCEFILE
exec $VIM "$@"
fi
else
#echo "Opening..." $SOURCEFILE
exec $VIM "$@"
fi