git-extras.plugin.zsh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #compdef git
  2. # ------------------------------------------------------------------------------
  3. # Description
  4. # -----------
  5. #
  6. # Completion script for git-extras (http://github.com/visionmedia/git-extras).
  7. #
  8. # ------------------------------------------------------------------------------
  9. # Authors
  10. # -------
  11. #
  12. # * Alexis GRIMALDI (https://github.com/agrimaldi)
  13. #
  14. # ------------------------------------------------------------------------------
  15. # Inspirations
  16. # -----------
  17. #
  18. # * git-extras (http://github.com/visionmedia/git-extras)
  19. # * git-flow-completion (http://github.com/bobthecow/git-flow-completion)
  20. #
  21. # ------------------------------------------------------------------------------
  22. __git_command_successful () {
  23. if (( ${#pipestatus:#0} > 0 )); then
  24. _message 'not a git repository'
  25. return 1
  26. fi
  27. return 0
  28. }
  29. __git_tag_names() {
  30. local expl
  31. declare -a tag_names
  32. tag_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
  33. __git_command_successful || return
  34. _wanted tag-names expl tag-name compadd $* - $tag_names
  35. }
  36. __git_branch_names() {
  37. local expl
  38. declare -a branch_names
  39. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  40. __git_command_successful || return
  41. _wanted branch-names expl branch-name compadd $* - $branch_names
  42. }
  43. __git_feature_branch_names() {
  44. local expl
  45. declare -a branch_names
  46. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/feature 2>/dev/null)"}#refs/heads/feature/})
  47. __git_command_successful || return
  48. _wanted branch-names expl branch-name compadd $* - $branch_names
  49. }
  50. __git_refactor_branch_names() {
  51. local expl
  52. declare -a branch_names
  53. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/refactor 2>/dev/null)"}#refs/heads/refactor/})
  54. __git_command_successful || return
  55. _wanted branch-names expl branch-name compadd $* - $branch_names
  56. }
  57. __git_bug_branch_names() {
  58. local expl
  59. declare -a branch_names
  60. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/bug 2>/dev/null)"}#refs/heads/bug/})
  61. __git_command_successful || return
  62. _wanted branch-names expl branch-name compadd $* - $branch_names
  63. }
  64. __git_submodule_names() {
  65. local expl
  66. declare -a submodule_names
  67. submodule_names=(${(f)"$(_call_program branchrefs git submodule status | awk '{print $2}')"})
  68. __git_command_successful || return
  69. _wanted submodule-names expl submodule-name compadd $* - $submodule_names
  70. }
  71. __git_author_names() {
  72. local expl
  73. declare -a author_names
  74. author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
  75. __git_command_successful || return
  76. _wanted author-names expl author-name compadd $* - $author_names
  77. }
  78. _git-changelog() {
  79. _arguments \
  80. '(-l --list)'{-l,--list}'[list commits]' \
  81. }
  82. _git-effort() {
  83. _arguments \
  84. '--above[ignore file with less than x commits]' \
  85. }
  86. _git-contrib() {
  87. _arguments \
  88. ':author:__git_author_names'
  89. }
  90. _git-count() {
  91. _arguments \
  92. '--all[detailed commit count]'
  93. }
  94. _git-delete-branch() {
  95. _arguments \
  96. ':branch-name:__git_branch_names'
  97. }
  98. _git-delete-submodule() {
  99. _arguments \
  100. ':submodule-name:__git_submodule_names'
  101. }
  102. _git-delete-tag() {
  103. _arguments \
  104. ':tag-name:__git_tag_names'
  105. }
  106. _git-extras() {
  107. local curcontext=$curcontext state line ret=1
  108. declare -A opt_args
  109. _arguments -C \
  110. ': :->command' \
  111. '*:: :->option-or-argument' && ret=0
  112. case $state in
  113. (command)
  114. declare -a commands
  115. commands=(
  116. 'update:update git-extras'
  117. )
  118. _describe -t commands command commands && ret=0
  119. ;;
  120. esac
  121. _arguments \
  122. '(-v --version)'{-v,--version}'[show current version]' \
  123. }
  124. _git-graft() {
  125. _arguments \
  126. ':src-branch-name:__git_branch_names' \
  127. ':dest-branch-name:__git_branch_names'
  128. }
  129. _git-squash() {
  130. _arguments \
  131. ':branch-name:__git_branch_names'
  132. }
  133. _git-feature() {
  134. local curcontext=$curcontext state line ret=1
  135. declare -A opt_args
  136. _arguments -C \
  137. ': :->command' \
  138. '*:: :->option-or-argument' && ret=0
  139. case $state in
  140. (command)
  141. declare -a commands
  142. commands=(
  143. 'finish:merge feature into the current branch'
  144. )
  145. _describe -t commands command commands && ret=0
  146. ;;
  147. (option-or-argument)
  148. curcontext=${curcontext%:*}-$line[1]:
  149. case $line[1] in
  150. (finish)
  151. _arguments -C \
  152. ':branch-name:__git_feature_branch_names'
  153. ;;
  154. esac
  155. esac
  156. }
  157. _git-refactor() {
  158. local curcontext=$curcontext state line ret=1
  159. declare -A opt_args
  160. _arguments -C \
  161. ': :->command' \
  162. '*:: :->option-or-argument' && ret=0
  163. case $state in
  164. (command)
  165. declare -a commands
  166. commands=(
  167. 'finish:merge refactor into the current branch'
  168. )
  169. _describe -t commands command commands && ret=0
  170. ;;
  171. (option-or-argument)
  172. curcontext=${curcontext%:*}-$line[1]:
  173. case $line[1] in
  174. (finish)
  175. _arguments -C \
  176. ':branch-name:__git_refactor_branch_names'
  177. ;;
  178. esac
  179. esac
  180. }
  181. _git-bug() {
  182. local curcontext=$curcontext state line ret=1
  183. declare -A opt_args
  184. _arguments -C \
  185. ': :->command' \
  186. '*:: :->option-or-argument' && ret=0
  187. case $state in
  188. (command)
  189. declare -a commands
  190. commands=(
  191. 'finish:merge bug into the current branch'
  192. )
  193. _describe -t commands command commands && ret=0
  194. ;;
  195. (option-or-argument)
  196. curcontext=${curcontext%:*}-$line[1]:
  197. case $line[1] in
  198. (finish)
  199. _arguments -C \
  200. ':branch-name:__git_bug_branch_names'
  201. ;;
  202. esac
  203. esac
  204. }
  205. zstyle ':completion:*:*:git:*' user-commands \
  206. changelog:'populate changelog file with commits since the previous tag' \
  207. contrib:'display author contributions' \
  208. count:'count commits' \
  209. delete-branch:'delete local and remote branch' \
  210. delete-submodule:'delete submodule' \
  211. delete-tag:'delete local and remote tag' \
  212. extras:'git-extras' \
  213. graft:'merge commits from source branch to destination branch' \
  214. squash:'merge commits from source branch into the current one as a single commit' \
  215. feature:'create a feature branch' \
  216. refactor:'create a refactor branch' \
  217. bug:'create a bug branch' \
  218. summary:'repository summary' \
  219. effort:'display effort statistics' \
  220. repl:'read-eval-print-loop' \
  221. commits-since:'list commits since a given date' \
  222. release:'release commit with the given tag' \
  223. alias:'define, search and show aliases' \
  224. ignore:'add patterns to .gitignore' \
  225. info:'show info about the repository' \
  226. create-branch:'create local and remote branch' \
  227. fresh-branch:'create empty local branch' \
  228. undo:'remove the latest commit' \
  229. setup:'setup a git repository' \
  230. touch:'one step creation of new files' \
  231. obliterate:'Completely remove a file from the repository, including past commits and tags' \
  232. local-commits:'list unpushed commits on the local branch' \