Created
September 28, 2011 09:36
-
-
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
This file contains 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
# 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