git-commit.plugin.zsh 1.1 KB

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