Skip to content

Instantly share code, notes, and snippets.

@GregOnNet
Last active February 3, 2016 11:42
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 GregOnNet/3424fef999d28444282a to your computer and use it in GitHub Desktop.
Save GregOnNet/3424fef999d28444282a to your computer and use it in GitHub Desktop.
Prefixing a commit
#!/bin/sh
#
# Usage
# workOnIssue <issue-number>
#
# Sample
# workOnIssue issue-999
#
function workOnIssue() {
PREFIX=$1;
BOLD_WHITE="\e[1;37m"
RESET_COLOR="\033[0m"
if [ -n "$PREFIX" ]; then
# Saving a commit message prefix
# in the global .gitconfig.
# It will be read by the hook to set the prefix
# in front of the commit message.
`git config --global prefix.commitMessage `"$PREFIX"`
printf "\r\n${BOLD_WHITE}Prefixing enabled${RESET_COLOR}\r\n";
printf "Make sure enabling the prepare-commit-msg hook\r\n"
printf "in your repsitory: http://git.io/vITez\r\n\r\n"
else
# If no prefix is passed the prefix will be
# removed from the global .gitconfig.
`git config --global prefix.commitMessage ""`
printf "\r\n${BOLD_WHITE}Prefixing disabled${RESET_COLOR}\r\n\r\n";
fi
}
#!/bin/sh
# setting up colors for console output
CYAN='\033[0;36m'
BOLD_CYAN='\033[1;36m'
RESET_COLOR='\033[0m'
COMMIT_PREFIX=`git config --global prefix.commitMessage`
COMMIT_MESSAGE=`cat "$1"`
# If an issue number exits it should be set
# before the commit message
if [ -n "$COMMIT_PREFIX" ]; then
printf "\r\n${CYAN}Prefixing commit message with ${BOLD_CYAN}$COMMIT_PREFIX${RESET_COLOR}\r\n"
echo "$COMMIT_PREFIX $COMMIT_MESSAGE" > "$1";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment