Last active
November 6, 2018 05:30
Star
You must be signed in to star a gist
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 | |
USAGE="USAGE: git append TEXT_TO_APPEND NUMBER_OF_COMMITS\nExample: git append \"#3301\" 5" | |
show_usage () { | |
echo -e "\n$USAGE" | |
} | |
case $1 in | |
help | -h | "/?") | |
show_usage | |
exit 1 | |
esac | |
if [ x = x${1} ] && [ x = x${2} ]; then | |
echo ">>> Both parameters are empty." | |
show_usage | |
exit 1 | |
fi | |
if [ x = x${2} ]; then | |
echo ">>> Second parameter is empty." | |
show_usage | |
exit 1 | |
fi | |
# Check if is integer | |
# https://unix.stackexchange.com/questions/151654/checking-if-an-input-number-is-an-integer | |
if ! [ "$2" -eq "$2" ] 2> /dev/null | |
then | |
echo ">>> Second parameter must be an integer!" | |
show_usage | |
exit 1 | |
fi | |
echo "You want to append text: \"$1\" to last $2 commits." | |
# https://stackoverflow.com/questions/226703/how-do-i-prompt-for-yes-no-cancel-input-in-a-linux-shell-script | |
while true; do | |
read -p "Do you want to continue [y/n]? " yn | |
case $yn in | |
[Yy]* ) git filter-branch -f --msg-filter 'sed "s/\(.*\)/\1 '$1'/g"' HEAD~$2..HEAD; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes [y] or no [n].";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment