Skip to content

Instantly share code, notes, and snippets.

@joshbode
Last active December 14, 2015 09:08
Show Gist options
  • Select an option

  • Save joshbode/5062813 to your computer and use it in GitHub Desktop.

Select an option

Save joshbode/5062813 to your computer and use it in GitHub Desktop.
Wrapper for git to use gvim under cygwin/msysgit for editing, diffing and merging. Handles quoting and path conversion.
#!/bin/sh
# gvim wrapper for git on cygwin and msysgit
# Josh Bode <[email protected]>
#
# .gitconfig setup:
#
# [core]
# editor = gvim-git.sh
#
# [merge]
# tool = custom
# [mergetool "custom"]
# cmd = gvim-git.sh -d \"$LOCAL\" \"$MERGED\" \"$REMOTE\"
#
# [diff]
# tool = custom
# [difftool "custom"]
# cmd = gvim-git.sh -Rd \"$LOCAL\" \"$REMOTE\"
# windows gvim likes paths like this
function path() {
if [[ "$OSTYPE" == "cygwin" ]]; then
echo $(cygpath --absolute --mixed "$1")
elif [[ "$OSTYPE" == "msys" ]]; then
FILE=$(basename "$1")
DIR=$(dirname "$1")
DIR=$((cd "$DIR" 2</dev/null && pwd -W) || echo "$DIR" | sed -e 's/\\/\//g')
echo $(echo "$DIR/$FILE")
fi
}
# get rid of home so gvim can find the windows home, not the cygwin home
export HOME=""
# switch arguments
command="gvim"
# add path arguments and quote them good. real good
for arg in "$@"; do
if [ -f "$arg" ]; then
command=" $command \"$(path "$arg")\""
else
command=" $command $arg"
fi
done
# eval so the quotes don't get eaten
eval "$command"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment