Parent directory

git-commit.plugin.zsh

1110 bytes
 1local _rev="$(git -C $ZSH rev-parse HEAD 2> /dev/null)"
 2if [[ $_rev == $(git config --global --get oh-my-zsh.git-commit-alias 2> /dev/null) ]]; then
 3  return
 4fi
 5git config --global oh-my-zsh.git-commit-alias "$_rev"
 6
 7local -a _git_commit_aliases
 8_git_commit_aliases=(
 9  'build'
10  'chore'
11  'ci'
12  'docs'
13  'feat'
14  'fix'
15  'perf'
16  'refactor'
17  'revert'
18  'style'
19  'test'
20  'wip'
21)
22
23local _alias _type
24for _type in "${_git_commit_aliases[@]}"; do
25  # an alias can't be named "revert" because the git command takes precedence
26  # https://stackoverflow.com/a/3538791
27  case "$_type" in
28    revert) _alias=rev ;;
29    *) _alias=$_type ;;
30  esac
31
32  local _func='!a() {
33local _scope _attention _message
34while [ $# -ne 0 ]; do
35case $1 in
36  -s | --scope )
37    if [ -z $2 ]; then
38      echo "Missing scope!"
39      return 1
40    fi
41    _scope="$2"
42    shift 2
43    ;;
44  -a | --attention )
45    _attention="!"
46    shift 1
47    ;;
48  * )
49    _message="${_message} $1"
50    shift 1
51    ;;
52esac
53done
54git commit -m "'$_type'${_scope:+(${_scope})}${_attention}:${_message}"
55}; a'
56
57  git config --global alias.$_alias "$_func"
58done