-
-
Save masukomi/7ab49186d53fd8eaa9a571fe5491890b to your computer and use it in GitHub Desktop.
find the last thing edited and add it to git. (Git Add Last Edited)
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/sh | |
# find the last thing edited and add it to git. | |
# useful when you're editing items in a merge conflict | |
# and are running a command to edit each file in the command line. | |
# Run gale after each edit so that the list of conflicting items gets shorter | |
# and you don't have to keep copy pasting the name of the file | |
HISTFILE=~/.bash_history | |
set -o history | |
LAST_FILE=$(history \ | |
| cut -c 8- \ | |
| grep --color=none "^$EDITOR" \ | |
| tail -n 1 | sed "s/$EDITOR //" \ | |
| sed -E 's/[[:space:]]+$//') | |
git add $LAST_FILE | |
if [ $? -eq 0 ]; then | |
echo "added $LAST_FILE" | |
else | |
echo "problems encountered adding $LAST_FILE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment