#!/bin/bash
# This UNIX shell script makes graphical Vim use one instance where possible.
# Save this script as ~/bin/gvim, make sure it's executable and you're off!
# Configuration variables.
GVIM=/usr/local/bin/gvimWMCTRL=/usr/bin/wmctrl# <- try `sudo apt-get install wmctrl'
DEBUG=no# yes or no
# Look for command-line arguments that aren't filenames and
# if one is found then fall back to Vim's regular behavior.
forARGin"$@";doifecho"$ARG"|grep-q'^note:';then# Don't consider "note:..." as non-file argument (this is a
# hack to make my note taking plug-in work with this script).
continueelif[!-f"$ARG"];then# Replace the wrapper with Vim itself.
[$DEBUG=yes]&&echo"Process $$: Executing $GVIM $@">&2exec$GVIM"$@"exit# <- shouldn't be reached!
fidone# Check if Vim is already running.
if!pidof$GVIM>/dev/null;then# It's not: Open file(s) in new instance.
[$DEBUG=yes]&&"Process $$: Executing $GVIM -p $@">&2exec"$GVIM"-p"$@"else[$DEBUG=yes]&&echo"Process $$: Requesting server list">&2$GVIM--serverlist|grep'^GVIM[0-9]*$'|whilereadVIM_SERVER_NAME;do[$DEBUG=yes]&&echo"Process $$: Raising selected Vim server">&2$WMCTRL-xa$VIM_SERVER_NAME# Pass any pathname arguments on to Vim?
if[$# -ge 1 ]; then
# Open files on command-line in existing Vim window.
[$DEBUG=yes]&&echo"Process $$: Executing $GVIM --servername '$VIM_SERVER_NAME' --remote-tab-silent $@">&2exec$GVIM--servername"$VIM_SERVER_NAME"--remote-tab-silent"$@"fidonefi

AltStyle によって変換されたページ (->オリジナル) /