git-commit.plugin.zsh 772 B

1234567891011121314151617181920212223242526272829303132
  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. 'wip'
  15. )
  16. local alias type
  17. for type in "${_git_commit_aliases[@]}"; do
  18. # an alias can't be named "revert" because the git command takes precedence
  19. # https://stackoverflow.com/a/3538791
  20. case "$type" in
  21. revert) alias=rev ;;
  22. *) alias=$type ;;
  23. esac
  24. 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'
  25. if ! git config --global --get-all alias.${alias} >/dev/null 2>&1; then
  26. git config --global alias.${alias} "$func"
  27. fi
  28. done
  29. unset _git_commit_aliases alias type func