Skip to content

Instantly share code, notes, and snippets.

@tomnomnom
Created September 28, 2011 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomnomnom/1247480 to your computer and use it in GitHub Desktop.
Save tomnomnom/1247480 to your computer and use it in GitHub Desktop.
bash function to open files modified in a git commit in vim tabs
# Open files modified in a git commit in vim tabs; defaults to HEAD. Pop it in your .bashrc
# Examples:
# virev 49808d5
# virev HEAD~3
function virev {
commit=$1
if [ -z "${commit}" ]; then
commit="HEAD"
fi
rootdir=$(git rev-parse --show-toplevel)
sourceFiles=$(git show --name-only --pretty="format:" ${commit} | grep -v '^$')
toOpen=""
for file in ${sourceFiles}; do
file="${rootdir}/${file}"
if [ -e "${file}" ]; then
toOpen="${toOpen} ${file}"
fi
done
if [ -z "${toOpen}" ]; then
echo "No files were modified in ${commit}"
return 1
fi
vim -p ${toOpen}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment