Last active
August 29, 2015 14:11
-
-
Save KeithHanlan/055e80df706b899080f7 to your computer and use it in GitHub Desktop.
GVim wrapper for git repo-specific servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This wrapper is in response to Neils de Vos' blog post | |
# "Changing vim settings depending on the git repository containing the file" | |
# (http://blog.nixpanic.net/2013/01/changing-vim-settings-depending-on-git.html) | |
# | |
# Since different repos have different coding standards, I want to be able to use Neils' method | |
# of selectively setting editor options based on file location. This is made simpler if I don't | |
# need to worry about making these settings buffer local. So, for example, if I only want to trim | |
# trailing whitespace and expand tabs in some some repos, I can have the following in my ~/.vimrc | |
# fun! <SID>ExpandTabs() | |
# let l = line(".") | |
# let c = col(".") | |
# %!expand | |
# call cursor(l,c) | |
# endfun | |
# | |
# let git_noexpandtabs = system("git config --get vim.settings") | |
# if strlen(git_noexpandtabs) | |
# autocmd FileType c,cpp,java,php,python,xml,make autocmd BufWritePre <buffer> :%s/\s\+$//e | |
# autocmd FileType c,cpp,java,php,xpython,ml autocmd BufWritePre <buffer> :call <SID>ExpandTabs() | |
# endif | |
gvim=${HOME}/bin/gvim | |
[ -x $gvim ] || gvim="gvim" | |
if [ "$1" != "-r" ]; then # I could do a more exhaustive job of handling gvim options | |
# but on the rare occassion when I want to use something | |
# other than -r, I can always invoke "gvim" directly. | |
if [ -n "$1" ]; then | |
for file in "$@"; do | |
pushd `dirname $file` > /dev/null | |
REPO=$(git rev-parse --show-toplevel 2>/dev/null) | |
[ -n "$REPO" ] && REPO=$(basename $REPO) | |
popd > /dev/null | |
remote="--remote-silent $file" | |
if [ -n "$REPO" ]; then | |
echo "Using GVIM servername $REPO for $file" >&2 # This might get annoying | |
$gvim --servername $REPO $remote | |
else | |
$gvim $file | |
fi | |
done | |
else | |
exec $gvim | |
fi | |
else | |
exec $gvim "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment