git-commit.plugin.zsh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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() {
  29. local _scope _attention _message
  30. while [ $# -ne 0 ]; do
  31. case $1 in
  32. -s | --scope )
  33. if [ -z $2 ]; then
  34. echo "Missing scope!"
  35. return 1
  36. fi
  37. _scope="$2"
  38. shift 2
  39. ;;
  40. -a | --attention )
  41. _attention="!"
  42. shift 1
  43. ;;
  44. * )
  45. _message+=" $1"
  46. shift 1
  47. ;;
  48. esac
  49. done
  50. git commit -m "'$_type'${_scope:+(${_scope})}${_attention}:${_message}"
  51. }; a'
  52. git config --global alias.$_alias "$_func"
  53. done
  54. git config --global oh-my-zsh.git-commit-alias "true"