git-commit.plugin.zsh 764 B

12345678910111213141516171819202122232425262728293031
  1. local -a _git_commit_aliases
  2. _git_commit_aliases=(
  3. 'build'
  4. 'chore'
  5. 'ci'
  6. 'docs'
  7. 'feat'
  8. 'fix'
  9. 'perf'
  10. 'refactor'
  11. 'revert'
  12. 'style'
  13. 'test'
  14. )
  15. local alias type
  16. for type in "${_git_commit_aliases[@]}"; do
  17. # an alias can't be named "revert" because the git command takes precedence
  18. # https://stackoverflow.com/a/3538791
  19. case "$type" in
  20. revert) alias=rev ;;
  21. *) alias=$type ;;
  22. esac
  23. 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'
  24. if ! git config --global --get-all alias.${alias} >/dev/null 2>&1; then
  25. git config --global alias.${alias} "$func"
  26. fi
  27. done
  28. unset _git_commit_aliases alias type func