-
Notifications
You must be signed in to change notification settings - Fork 32
/
drop
executable file
·52 lines (45 loc) · 1.44 KB
/
drop
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
#! /bin/sh
if [ -z "$1" ]; then
echo "usage: drop {filename}"
exit 0
fi
if [ -z "$VIM_EXE" ]; then
echo "Must be called inside vim/neovim"
exit 1
fi
absolute_path() {
local result=""
if [ -x "$(which realpath 2> /dev/null)" ]; then
result="$(realpath -s """$1""" 2> /dev/null)"
fi
if [ -z "$result" ] && [ -x "$(which perl 2> /dev/null)" ]; then
result="$(perl -MCwd -e 'print Cwd::realpath($ARGV[0])' """$1""")"
fi
if [ -z "$result" ] && [ -x "$(which python 2> /dev/null)" ]; then
result="$(python -c 'import sys, os;sys.stdout.write(os.path.abspath(sys.argv[1]))' """$1""")"
fi
if [ -z "$result" ] && [ -x "$(which python3 2> /dev/null)" ]; then
result="$(python3 -c 'import sys, os;sys.stdout.write(os.path.abspath(sys.argv[1]))' """$1""")"
fi
if [ -z "$result" ] && [ -x "$(which python2 2> /dev/null)" ]; then
result="$(python2 -c 'import sys, os;sys.stdout.write(os.path.abspath(sys.argv[1]))' """$1""")"
fi
if [ -z "$result" ] && [ -x "$(which realpath 2> /dev/null)" ]; then
result="$(realpath """$1""")"
fi
if [ -z "$result" ]; then
result="$1"
fi
echo $result
}
name="$(absolute_path """$1""")"
if [ -z "$NVIM_LISTEN_ADDRESS" ]; then
printf '\033]51;["call", "Tapi_TerminalEdit", ["%s"]]\007' "$name"
else
if [ -x "$(which nvr 2> /dev/null)" ]; then
nvr --servername "$VIM_SERVERNAME" --remote-expr "Tapi_TerminalEdit(0, '$name')"
else
echo "cannot find nvr executable, please install neovim-remote"
exit 2
fi
fi