-
-
Save sarangnx/c4f6384dd3d425973bd56ca64a394154 to your computer and use it in GitHub Desktop.
Git Semantic commit.
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 | |
printUsage() { | |
cat <<EOM | |
Usage: cm [OPTION]... [MESSAGE] | |
Options: | |
--scope,-s Scope of the change. | |
Commit Types | |
--bulid Changes related to configs, dependencies etc. | |
--docs Changes related to documentation. | |
--feat New feature | |
--fix Bug fixes | |
--refactor, --ref Changes like renaming variables, removing redundant code, | |
simplifying the code etc. | |
--style Changes like addition of trailing commas, changing quotes | |
intendation etc. | |
--test Addition or refactoring of tests. | |
EOM | |
} | |
commit_type='' | |
commit_scope='' | |
commit_message='' | |
remains=() | |
for arg in "$@" | |
do | |
case $arg in | |
--build) | |
commit_type="build" | |
shift | |
;; | |
--docs) | |
commit_type="docs" | |
shift | |
;; | |
--feat) | |
commit_type="feat" | |
shift | |
;; | |
--fix) | |
commit_type="fix" | |
shift | |
;; | |
--refactor|--ref) | |
commit_type="refactor" | |
shift | |
;; | |
--style) | |
commit_type="style" | |
shift | |
;; | |
--test) | |
commit_type="test" | |
shift | |
;; | |
--scope|-s) | |
commit_scope="$2" | |
shift | |
shift | |
;; | |
--help|-h) | |
printUsage | |
exit 1 | |
;; | |
*) | |
if [[ $1 =~ ^- ]]; then | |
remains+=("$1") | |
elif [[ ! -z $1 ]]; then | |
commit_message=$1 | |
fi | |
shift | |
;; | |
esac | |
done | |
# array of commit_types | |
types=( "build" "docs" "feat" "fix" "refactor" "style" "test" ) | |
found=false | |
# check if a type is selected | |
for i in "${types[@]}" | |
do | |
if [[ "$i" == "$commit_type" ]]; then | |
found=true | |
break | |
fi | |
done | |
if [[ $found == false ]]; then | |
echo -e "Type Required.\n" | |
printUsage | |
exit 1 | |
fi | |
if [[ ! -z $commit_scope ]]; then | |
commit_scope="($commit_scope)" | |
fi | |
git commit -m "${commit_type}${commit_scope}: ${commit_message}" ${remains[*]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment