forked from mikezackles/vranger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvrim
More file actions
executable file
·61 lines (51 loc) · 1.77 KB
/
vrim
File metadata and controls
executable file
·61 lines (51 loc) · 1.77 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
#!/bin/sh
# Drop the "--" argument if present.
# Ranger passes "--" to indicate the end of the arguments, but vim treats it
# as a filename after the --remote family of arguments.
if [ "$1" == "--" ]; then
shift
fi
# Exit if we don't know what server/session to use
if [ -z "$VRIM_ID" ]; then
echo "VRIM_ID not set!" >&2
echo "vrim is not meant to be invoked directly" >&2
exit 1
fi
# Exit if we don't have a DETACH mapping
if [ -z "$DETACH" ]; then
echo "DETACH not set!" >&2
echo "vrim is not meant to be invoked directly" >&2
exit 1
fi
REMAP="nnoremap <silent> $DETACH :call system(\"tmux detach -s $VRIM_ID\")"
if [ "$VRIM_SENDKEYS" = "1" ]; then
REMAP="$REMAP<CR>"
START_VIM_SERVER="vim -c '$REMAP' \"$@\""
else
# note the <LT> workaround to prevent literal <CR>
# being interpreted by --remote-silent
REMAP="$REMAP<LT>CR>"
# I haven't found a way to prevent vim from opening a [No Name] buffer first.
# This deletes the first buffer.
REMOVE_BLANK_BUFFER="bd1"
START_VIM_SERVER="vim --servername $VRIM_ID --remote-silent +'$REMOVE_BLANK_BUFFER | $REMAP' \"$@\""
fi
# Check to see if tmux session is running
if ! tmux has-session -t $VRIM_ID >/dev/null 2>&1; then
# Start vim server and containing tmux session
REATTACH=$(which reattach-to-user-namespace 2>/dev/null)
if [ -x "$REATTACH" ]; then
START_VIM_SERVER="$REATTACH $START_VIM_SERVER"
fi
exec tmux -2 new-session -s $VRIM_ID "$START_VIM_SERVER" \; set status off \; >/dev/null 2>&1
else
# Open requested file and attach to server
if [ "$VRIM_SENDKEYS" = "1" ]; then
tmux send-keys -t $VRIM_ID Escape
tmux send-keys -t $VRIM_ID -l ":e $@"
tmux send-keys -t $VRIM_ID Enter
else
vim --servername $VRIM_ID --remote "$@"
fi
exec tmux -2 attach -t $VRIM_ID >/dev/null 2>&1
fi