-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtab
93 lines (83 loc) · 2.18 KB
/
gtab
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/bash
#
# Bash gvim helper
#
#suppress GTK warning about unknonwn characters. You may adjust/change this if it's causing you problems
export LC_ALL=C
# usage
function show_help()
{
echo "command:"
echo "gtab [option] file1 file2 ..."
echo "options:"
echo "-h/-?/--help: usage"
echo "-l/--list: list available gvim instances"
echo "-s servername/--server servername: user specified gvim server "
}
HOST_UNAME="$(uname -s)"
host_os=Linux
case "${HOST_UNAME}" in
CYGWIN*) host_os=Cygwin;;
Linux*) host_os=Linux;;
SunOS*) host_os=Solaris;;
esac
#Generate unique instance
SERVERNAME="`hostname`:`basename \`pwd\``:$PPID"
# test instances
SERVERLIST=
if [ $host_os == "Solaris" ]
then
SERVERLIST=$( grep "^gvim" /proc/*/cmdline |xargs -0 -n 3|awk '{print $3}')
else
SERVERLIST=$(grep -a "^gvim" /proc/*/cmdline |xargs -0|awk -F ' ' '{print $3}')
fi
# parse args
while :; do
case $1 in
(-h|-\?|--help):
show_help
exit 0
;;
(-l|--list):
echo "$SERVERLIST"
exit 0
;;
(-s|--server):
if [[ -z "$2" ]]
then
echo "error: specify a server name with -s/--server option"
exit 1
fi
SERVERNAME="$2"
shift
shift
;;
(-?*):
printf 'ERR: Unknown option: %s\n' "$1" >&2
show_help
exit 1
;;
(*):
# Default case: No more options, so break out of the loop.
break
;;
esac
done
IS_EXISTING_SERVER=$(echo $SERVERLIST | grep $SERVERNAME)
if [[ ! $IS_EXISTING_SERVER ]]; then
echo "starting gvim id '$SERVERNAME'"
gvim --servername "${SERVERNAME}"
else
# test if trying to start another instance in same dir
if [[ -z "$1" ]]
then
echo "info: an instance of gvim already running for $SERVERNAME"
echo "direcly use it or start another instance with a new servername"
exit 0
fi
fi
if [[ $1 ]]; then
echo "Tabing ${@} to gvim id '$SERVERNAME'"
gvim --servername "${SERVERNAME}" --remote-tab "${@}"
fi
exit 0