Skip to content

Instantly share code, notes, and snippets.

@masukomi
Last active December 20, 2016 20:43
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 masukomi/7ab49186d53fd8eaa9a571fe5491890b to your computer and use it in GitHub Desktop.
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)
#!/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