├── .git-ch ├── .git-rf ├── README.md ├── git-chore ├── git-docs ├── git-feat ├── git-fix ├── git-localize ├── git-refactor ├── git-style ├── git-test └── install.sh /.git-ch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./git-chore $@ 3 | -------------------------------------------------------------------------------- /.git-rf: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./git-rf $@ 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Semantic Git commit messages 2 | 3 | Inspired by Sparkbox's awesome article on [semantic commit messages](http://seesparkbox.com/foundry/semantic_commit_messages). 4 | 5 | ## What is this? 6 | These are **very simple** custom git commands that enforce the git user to write better git commit messages. If still confused, read the article above. 7 | 8 | ## Installation: 9 | 10 | 1. Clone this repo, preferably in your `$HOME` directory. 11 | ``` 12 | git clone https://github.com/fteem/git-semantic-commits ~/.git-semantic-commits 13 | ``` 14 | 15 | > Tip: If you're using Cygwin, open it and type `echo $USERPROFILE`. This will show you the location of the `$HOME` directory. 16 | 17 | 2. Install it as a set of bash scripts or git aliases: 18 | * bash scripts 19 | ``` 20 | cd ~/.git-semantic-commits && ./install.sh --scripts 21 | ``` 22 | * git aliases 23 | ``` 24 | cd ~/.git-semantic-commits && ./install.sh 25 | ``` 26 | 27 | > Tip: Installation script is idempotent and could be harmlessly executed multiple times. It adds bash scripts to the PATH in your `~/.bashrc` or `~/.zshrc` files or adds git aliases to the `~/.gitconfig` file respectively (without any duplication). 28 | 29 | 3. Commit away! 30 | 31 | ## Usage 32 | 33 | There are 8 new Git commands now. 34 | 35 | New command -> what it does: 36 | 37 | * ```git feat "commit message here"``` -> ```git commit -m 'feat: commit message here'``` 38 | * ```git docs "commit message here"``` -> ```git commit -m 'docs: commit message here'``` 39 | * ```git chore "commit message here"``` -> ```git commit -m 'chore: commit message here'``` 40 | * ```git fix "commit message here"``` -> ```git commit -m 'fix: commit message here'``` 41 | * ```git refactor "commit message here"``` -> ```git commit -m 'refactor: commit message here'``` 42 | * ```git style "commit message here"``` -> ```git commit -m 'style: commit message here'``` 43 | * ```git test "commit message here"``` -> ```git commit -m 'test: commit message here'``` 44 | * ```git localize "commit message here"``` -> ```git commit -m 'localize: commit message here'``` 45 | 46 | If you would like to add an optional scope, as described [here](https://conventionalcommits.org/), use the '-s' flag and quote the scope message: 47 | 48 | * ```git docs -s "scope here" "commit message here"``` -> ```git commit -m 'docs(scope here): commit message here'``` 49 | 50 | If you would still like to use your text editor for your commit messages 51 | you can omit the message, and do your commit message in your editor. 52 | 53 | * ```git feat``` -> ```git commit -m 'feat: ' -e``` 54 | 55 | Aliases for those who use [git-extras](https://github.com/tj/git-extras) (will be installed only if you have `git-extras`): 56 | 57 | * ```git rf "commit message here"``` -> ```git commit -m 'refactor: commit message here'``` 58 | * ```git ch "commit message here"``` -> ```git commit -m 'chore: commit message here'``` 59 | 60 | ## Uninstallation 61 | 62 | You can manually uninstall `git-semantic-commits` by: 63 | * Removing the added aliases from `~/.gitconfig`. 64 | * Removing the line added to the `$PATH` variable from `~/.bashrc`. 65 | 66 | ## How to contribute 67 | Open a pull request/issue or fork this repo and submit your changes via a pull request. 68 | -------------------------------------------------------------------------------- /git-chore: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "chore: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "chore(${2}): ${@:3}" 8 | else 9 | git commit -m "chore: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-docs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "docs: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "docs(${2}): ${@:3}" 8 | else 9 | git commit -m "docs: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-feat: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "feat: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "feat(${2}): ${@:3}" 8 | else 9 | git commit -m "feat: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-fix: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "fix: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "fix(${2}): ${@:3}" 8 | else 9 | git commit -m "fix: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-localize: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "localize: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "localize(${2}): ${@:3}" 8 | else 9 | git commit -m "localize: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-refactor: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "refactor: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "refactor(${2}): ${@:3}" 8 | else 9 | git commit -m "refactor: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-style: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "style: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "style(${2}): ${@:3}" 8 | else 9 | git commit -m "style: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /git-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ] 3 | then 4 | git commit -m "test: " -e 5 | elif [ "$1" == "-s" ] 6 | then 7 | git commit -m "test(${2}): ${@:3}" 8 | else 9 | git commit -m "test: ${@}" 10 | fi 11 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CWD=`pwd` 3 | 4 | # Register semantic commits scripts execution path 5 | # 6 | # $1 — shell configuraton file path 7 | function register_path { 8 | PATH_LINE='export PATH=$PATH:'$CWD':$PATH' 9 | 10 | if [ -f $1 ]; then 11 | if ! grep -Fxq "$PATH_LINE" $1; then 12 | echo 13 | echo "Adding path to $1" 14 | echo $PATH_LINE >> $1 15 | source $1 16 | fi 17 | fi 18 | } 19 | 20 | # Register semantic commits git aliases 21 | # 22 | # $1 — git alias and semantic message prefix 23 | # [$2] — (optional) custom semantic message prefix 24 | function register_git_alias { 25 | if ! git config --global --get-all alias.$1 &>/dev/null; then 26 | if [[ -z $2 ]]; then 27 | git config --global alias.$1 '!f() { [[ -z "$GIT_PREFIX" ]] || cd "$GIT_PREFIX" && if [ -z "$1" ]; then git commit -m "'$1': " -e; elif [ "$1" == "-s" ]; then git commit -m "'$1'(${2}): ${@:3}"; else git commit -m "'$1': ${@}"; fi }; f' 28 | 29 | else 30 | git config --global alias.$1 '!f() { [[ -z "$GIT_PREFIX" ]] || cd "$GIT_PREFIX" && if [ -z "$1" ]; then git commit -m "'$2': " -e; elif [ "$1" == "-s" ]; then git commit -m "'$2'(${2}): ${@:3}"; else git commit -m "'$2': ${@}"; fi }; f' 31 | fi 32 | fi 33 | } 34 | 35 | # Check if command was finished successfully 36 | # 37 | # $1 — any shell command 38 | function command_succes { 39 | command $1 >/dev/null 2>&1 && return 0 # true 40 | return 1 # false 41 | } 42 | 43 | if [[ -n $1 ]] && [[ $1 == '--scripts' ]]; then 44 | echo 'Installing scripts…' 45 | 46 | register_path ~/.bashrc 47 | register_path ~/.zshrc 48 | 49 | # git-extras chore/refactor compatibility (https://github.com/tj/git-extras) 50 | # Docs: https://github.com/tj/git-extras/blob/master/Commands.md#git-featurerefactorbugchore 51 | if command_succes 'git extras'; then 52 | extra_aliases=( 'ch' 'rf' ) 53 | for extra_alias in "${extra_aliases[@]}"; do 54 | mv $CWD/.git-$extra_alias $CWD/git-$extra_alias 55 | done 56 | fi 57 | else 58 | echo 'Installing git aliases…' 59 | 60 | semantic_aliases=( 'chore' 'docs' 'feat' 'fix' 'localize' 'chore' 'refactor' 'style' 'test' ) 61 | 62 | for semantic_alias in "${semantic_aliases[@]}"; do 63 | register_git_alias $semantic_alias 64 | done 65 | 66 | # git-extras chore/refactor compatibility (https://github.com/tj/git-extras) 67 | # Docs: https://github.com/tj/git-extras/blob/master/Commands.md#git-featurerefactorbugchore 68 | if command_succes 'git extras'; then 69 | register_git_alias 'ch' 'chore' 70 | register_git_alias 'rf' 'refactor' 71 | fi 72 | fi 73 | 74 | echo 75 | echo 'Done! Now you can use semantic commits.' 76 | echo 'See: https://github.com/fteem/git-semantic-commits for more information.' 77 | --------------------------------------------------------------------------------