Created
November 3, 2016 21:36
-
-
Save stefco/10ac2926495d0f85fc0817edf4037279 to your computer and use it in GitHub Desktop.
Vim edit, git add, commit, push loop functions
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
# git add, commit, and push | |
gadcmtpu () { | |
if ! [ $# -eq 1 ]; then | |
echo "ERROR: 1 argument required" | |
echo "Usage: gadcmtpu filename" | |
exit 1 | |
fi | |
echo 'COMMITTING AND PUSHING.' | |
echo 'CURRENT STATUS:' | |
echo | |
git status | |
git add "$1" | |
echo | |
echo "$1 ADDED" | |
echo | |
git status | |
read -e -p 'Commit message (empty to abort, KILL to errexit):' msg | |
if [ "$msg"1 = 1 ]; then | |
echo "Empty commit message, abort." | |
elif [ "$msg" = KILL ]; then | |
echo "Exiting with error code 2." | |
exit 2 | |
else | |
git commit -m "$msg" | |
git push | |
fi | |
} | |
# launch vim. on quit, git add, commit, and push | |
vigit () { | |
if ! [ $# -eq 1 ]; then | |
echo "ERROR: 1 argument required" | |
echo "Usage: vigit filename" | |
exit 1 | |
fi | |
( vim +'exe "normal \<C-o>"' "$1" && gadcmtpu "$1" ) || exit 2 | |
} | |
# Keep reopenning the file to continue the edit add commit push cycle | |
vigitr () { | |
while vigit "$1"; do | |
echo 'File saved, reopening.' | |
done | |
echo 'Exit signal received, stopping the loop.' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment