Skip to content

Instantly share code, notes, and snippets.

@AlexTalks
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexTalks/24dc517a19cb565c0693 to your computer and use it in GitHub Desktop.
Save AlexTalks/24dc517a19cb565c0693 to your computer and use it in GitHub Desktop.
GVIM Wrapper! One TTY one GVIM window...
# GVIM Wrapper!
# Usage: gvim [option] [file...] open files, tabbed, in a shared window (default one per terminal)
# Options: (only one can be used)
# -d, --dir Open files in a window specific to the current working directory
# -n, --normal Execute command without server arguments
# -s, --server <name> Open files in the window named <name>
# --print Print command with full arguments
# --usage Print this message and exit
vim-gui-server() {
local PROGRAM="$1"
local BIN=$(which $PROGRAM)
local NAME="`tty`"
shift
if [ "$1" == "-n" ] || [ "$1" == "--normal" ]; then
shift
eval "$BIN $@"
return $?
fi
if [ "$1" == "--print" ]; then
local BIN="echo $BIN"
shift
fi
if [ "$1" == "-d" ] || [ "$1" == "--dir" ]; then
local NAME="`pwd`"
shift
elif [ "$1" == "-s" ] || [ "$1" == "--server" ]; then
local NAME="$2"
shift 2
fi
if [ "$1" == "--usage" ]; then
echo "Usage: $PROGRAM [option] [file...] open files, tabbed, in a shared window (default one per terminal)"
echo "Options: (only one can be used)"
echo " -d, --dir Open files in a window specific to the current working directory"
echo " -n, --normal Execute command without server arguments"
echo " -s, --server <name> Open files in the window named <name>"
echo " --print Print command with full arguments"
echo " --usage Print this message and exit"
return 1
fi
local SERVERNAME="$PROGRAM $NAME"
local VIM_ARGS="--servername \"$SERVERNAME\""
$PROGRAM --serverlist | grep -q -i "$SERVERNAME"
if [ $? -eq 0 ]; then
if [ $# -ge 1 ]; then
local VIM_ARGS="$VIM_ARGS --remote-tab-silent"
else
local VIM_ARGS="$VIM_ARGS --remote-send \"<C-\><C-N>:call remote_foreground(\\\"$SERVERNAME\\\")<CR>\""
fi
fi
local cmd="$BIN $VIM_ARGS $@"
eval $cmd
return $?
}
alias gvim="vim-gui-server gvim"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment