Created
December 14, 2012 04:40
-
-
Save ethan605/4282727 to your computer and use it in GitHub Desktop.
Refine
This file contains hidden or 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 | |
function usage() { | |
echo "Usage: init <command>" | |
echo "Usage: <command> '<commit>' [-i, --ignore-ticket]" | |
} | |
if [ $# -eq 0 ] || [ $# -gt 2 ]; then | |
usage | |
exit 1 | |
fi | |
if [ "$1" == "init" ]; then | |
sudo cp commit.sh /usr/local/lib/ | |
if [ -e /usr/local/bin/$2 ]; then | |
sudo rm /usr/local/bin/$2 | |
fi | |
sudo ln -s /usr/local/lib/commit.sh /usr/local/bin/$2 | |
exit 0 | |
fi | |
if [ $# -eq 2 ]; then | |
if [ "$2" == "-i" ] || [ "$2" == "--ignore-ticket" ]; then | |
echo "Ticket number ignored" | |
git commit -am "$1" | |
else | |
usage | |
fi | |
exit 1 | |
fi | |
# Valid commit, process commit | |
if [ -n "$1" ] && [[ $1 =~ \#[0-9]+ ]]; then | |
echo "Valid commit, processing" | |
git commit -am "$1" | |
exit 0 | |
fi | |
# Invalid commit, prompt for ticket number | |
echo "Invalid commit! Don't mess with Alex >:)" | |
echo -e "Ticket number: \c" | |
read ticket | |
if [ -z $ticket ]; then | |
echo "Invalid ticket number, are you kidding me -_+? Try again!!!" | |
exit 1 | |
else | |
commit="[#"$ticket"] $1" | |
echo "Full commit:" $commit | |
git commit -am "$commit" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment