git-commit.plugin.zsh 880 B

123456789101112131415161718192021222324252627282930313233343536
  1. if git config --global --get-all alias.$_alias >/dev/null 2>&1 \
  2. && ! git config --global --get-all oh-my-zsh.git-commit-alias >/dev/null 2>&1; then
  3. return
  4. fi
  5. local -a _git_commit_aliases
  6. _git_commit_aliases=(
  7. 'build'
  8. 'chore'
  9. 'ci'
  10. 'docs'
  11. 'feat'
  12. 'fix'
  13. 'perf'
  14. 'refactor'
  15. 'revert'
  16. 'style'
  17. 'test'
  18. 'wip'
  19. )
  20. local _alias _type
  21. for _type in "${_git_commit_aliases[@]}"; do
  22. # an alias can't be named "revert" because the git command takes precedence
  23. # https://stackoverflow.com/a/3538791
  24. case "$_type" in
  25. revert) _alias=rev ;;
  26. *) _alias=$_type ;;
  27. esac
  28. local _func='!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$type'(${scope}): ${@}"; else git commit -m "'$type': ${@}"; fi }; a'
  29. git config --global alias.$_alias "$_func"
  30. done
  31. git config --global oh-my-zsh.git-commit-alias "true"