-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimwrap
executable file
·30 lines (24 loc) · 881 Bytes
/
vimwrap
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
#!/usr/bin/ruby
# wrapper for gvim && MacVim
# reuses existing Vim session if possible, launches new personal for user otherwise
# get vim binary
if `uname`.chomp == "Darwin"
vim = "/Applications/MacVim.app/Contents/MacOS/Vim"
else
vim = `which vim`
end
username = `whoami`.chomp
# run in tab in existing user session
`#{vim} --serverlist`.split("\n").each do |servername|
if servername =~ /#{username}/i
exec "#{vim} -g --servername #{servername} --remote-tab-silent \"#{$*}\" &>/dev/null"
end
end
# run in tab in existing general session, not for root
`#{vim} --serverlist`.split("\n").each do |serverrname|
if serverrname =~ /vim/i
exec "#{vim} -g --servername #{servername} --remote-tab-silent \"#{$*}\" &>/dev/null"
end
end if Process.uid == 0
# no existing sessions found, launch new one
exec "#{vim} -g --servername `whoami` \"#{$*}\" &>/dev/null"