-
-
Save arnorhs/1517095 to your computer and use it in GitHub Desktop.
gitopen - Open all files from a git diff or show command
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
#!/bin/bash | |
# This script will open all files from a git diff or a git show in vim. | |
# My bash skills are a bit primitive so this can probably be done more intelligently | |
# Usage: | |
# gitopen -- opens all added files that have changed since HEAD | |
# gitopen diff HEAD -- these are the default parameters | |
# gitopen diff master -- opens files that have changed from master | |
# gitopen show -- opens files that were changed in the last revision (HEAD) | |
# gitopen show HEAD -- default param, does the same | |
# gitopen show 4b3ca34 -- opens a particular REV | |
# It's set to use macvim as the default editor, you can change that easily by | |
# changing this line: | |
EDITOR=${EDITOR:-"$HOME/bin/mvim --remote-silent"} | |
COMMAND=diff | |
REV=HEAD | |
if [ $1 ]; then | |
COMMAND=$1 | |
fi | |
if [ $2 ]; then | |
REV=$2 | |
fi | |
if [ $COMMAND = "show" ]; then | |
PARAM='--pretty=format: --name-only' | |
else | |
PARAM='--name-only' | |
fi | |
git $COMMAND $PARAM $REV | xargs $EDITOR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is brilliant! Just what I needed. Thank you, @arnorhs! 🎉