1 # ------------------------------------------------------------------------------
5 # Completion script for git-extras (https://github.com/tj/git-extras).
7 # This depends on and reuses some of the internals of the _git completion
8 # function that ships with zsh itself. It will not work with the _git that ships
11 # ------------------------------------------------------------------------------
15 # * Alexis GRIMALDI (https://github.com/agrimaldi)
16 # * spacewander (https://github.com/spacewander)
18 # ------------------------------------------------------------------------------
22 # * git-extras (https://github.com/tj/git-extras)
23 # * git-flow-completion (https://github.com/bobthecow/git-flow-completion)
25 # ------------------------------------------------------------------------------
29 # These are a lot like their __git_* equivalents inside _git
31 __gitex_command_successful () {
32 if (( ${#*:#0} > 0 )); then
33 _message 'not a git repository'
41 git log --oneline -15 | sed 's/\([[:alnum:]]\{7\}\) /\1:/' | while read commit
43 hash=$(echo $commit | cut -d':' -f1)
44 commits[$hash]="$commit"
47 _describe -t commits commit commits && ret=0
50 __gitex_remote_names() {
52 declare -a remote_names
53 remote_names=(${(f)"$(_call_program remotes git remote 2>/dev/null)"})
54 __git_command_successful || return
55 _wanted remote-names expl remote-name compadd $* - $remote_names
61 tag_names=(${${(f)"$(_call_program tags git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
62 __git_command_successful || return
63 _wanted tag-names expl tag-name compadd $* - $tag_names
67 __gitex_branch_names() {
69 declare -a branch_names
70 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
71 __git_command_successful || return
72 _wanted branch-names expl branch-name compadd $* - $branch_names
75 __gitex_specific_branch_names() {
77 declare -a branch_names
78 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/"$1" 2>/dev/null)"}#refs/heads/$1/})
79 __git_command_successful || return
80 _wanted branch-names expl branch-name compadd - $branch_names
83 __gitex_chore_branch_names() {
84 __gitex_specific_branch_names 'chore'
87 __gitex_feature_branch_names() {
88 __gitex_specific_branch_names 'feature'
91 __gitex_refactor_branch_names() {
92 __gitex_specific_branch_names 'refactor'
95 __gitex_bug_branch_names() {
96 __gitex_specific_branch_names 'bug'
99 __gitex_submodule_names() {
101 declare -a submodule_names
102 submodule_names=(${(f)"$(_call_program branchrefs git submodule status | awk '{print $2}')"}) # '
103 __git_command_successful || return
104 _wanted submodule-names expl submodule-name compadd $* - $submodule_names
108 __gitex_author_names() {
110 declare -a author_names
111 author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
112 __git_command_successful || return
113 _wanted author-names expl author-name compadd $* - $author_names
119 '(--list -l)'{--list,-l}'[show authors]' \
120 '--no-email[without email]' \
124 local curcontext=$curcontext state line ret=1
129 '*:: :->option-or-argument' && ret=0
135 'finish:merge bug into the current branch'
137 _describe -t commands command commands && ret=0
140 curcontext=${curcontext%:*}-$line[1]:
144 ':branch-name:__gitex_bug_branch_names'
148 ':remote-name:__gitex_remote_names'
155 '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
161 '(-l --list)'{-l,--list}'[list commits]' \
165 local curcontext=$curcontext state line ret=1
170 '*:: :->option-or-argument' && ret=0
176 'finish:merge and delete the chore branch'
178 _describe -t commands command commands && ret=0
181 curcontext=${curcontext%:*}-$line[1]:
185 ':branch-name:__gitex_chore_branch_names'
189 ':remote-name:__gitex_remote_names'
196 '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
202 ':author:__gitex_author_names'
208 '--all[detailed commit count]'
211 _git-create-branch() {
212 local curcontext=$curcontext state line
215 '*:: :->option-or-argument'
220 '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
223 curcontext=${curcontext%:*}-$line[1]:
227 ':remote-name:__gitex_remote_names'
233 _git-delete-branch() {
235 ':branch-name:__gitex_branch_names'
239 _git-delete-submodule() {
241 ':submodule-name:__gitex_submodule_names'
247 ':tag-name:__gitex_tag_names'
253 '--above[ignore file with less than x commits]'
258 local curcontext=$curcontext state line ret=1
263 '*:: :->option-or-argument' && ret=0
269 'update:update git-extras'
271 _describe -t commands command commands && ret=0
276 '(-v --version)'{-v,--version}'[show current version]'
281 local curcontext=$curcontext state line ret=1
286 '*:: :->option-or-argument' && ret=0
292 'finish:merge feature into the current branch'
294 _describe -t commands command commands && ret=0
297 curcontext=${curcontext%:*}-$line[1]:
301 ':branch-name:__gitex_feature_branch_names'
305 ':remote-name:__gitex_remote_names'
312 '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
317 ':src-branch-name:__gitex_branch_names' \
318 ':dest-branch-name:__gitex_branch_names'
323 '(--email -e)'{--email,-e}'[display author emails instead of names]' \
324 '(--ignore-whitespace -w)'{--ignore-whitespace,-w}'[ignore whitespace only changes]' \
325 '(--debug -d)'{--debug,-d}'[output debug information]' \
326 '-h[output usage information]'
331 '(--local -l)'{--local,-l}'[show local gitignore]' \
332 '(--global -g)'{--global,-g}'[show global gitignore]' \
333 '(--private -p)'{--private,-p}'[show repo gitignore]'
339 '(--append -a)'{--append,-a}'[append .gitignore]' \
340 '(--replace -r)'{--replace,-r}'[replace .gitignore]' \
341 '(--list-in-table -l)'{--list-in-table,-l}'[print available types in table format]' \
342 '(--list-alphabetically -L)'{--list-alphabetically,-L}'[print available types in alphabetical order]' \
343 '(--search -s)'{--search,-s}'[search word in available types]'
348 _arguments '--ff-only[merge only fast-forward]'
350 ':src:__gitex_branch_names' \
351 ':dest:__gitex_branch_names'
356 ':first-branch-name:__gitex_branch_names' \
357 ':second-branch-name:__gitex_branch_names'
362 local curcontext=$curcontext state line ret=1
367 '*:: :->option-or-argument' && ret=0
373 'finish:merge refactor into the current branch'
375 _describe -t commands command commands && ret=0
378 curcontext=${curcontext%:*}-$line[1]:
382 ':branch-name:__gitex_refactor_branch_names'
386 ':remote-name:__gitex_remote_names'
393 '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
399 ':branch-name:__gitex_branch_names'
404 '(--replace -r)'{--replace,-r}'[replace stamps with same id]'
409 '-a[Specify the author of commits. Use "all" to specify all authors.]' \
410 '-d[Show history since N days ago]' \
411 '-D[Specify the date format displayed in commit history]' \
412 '-f[Fetch commits before showing history]' \
413 '-g[Display GPG signed info]' \
414 '-h[Display help message]' \
415 '-L[Enable the inclusion of symbolic links]' \
416 '-m[The depth of recursive directory search]'
420 _arguments '--line[summarize with lines rather than commits]'
427 '(--soft -s)'{--soft,-s}'[only rolls back the commit but changes remain un-staged]' \
428 '(--hard -h)'{--hard,-h}'[wipes your commit(s)]'
431 zstyle -g existing_user_commands ':completion:*:*:git:*' user-commands
433 zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
434 alias:'define, search and show aliases' \
435 archive-file:'export the current head of the git repository to an archive' \
436 authors:'generate authors report' \
437 back:'undo and stage latest commits' \
438 bug:'create bug branch' \
439 bulk:'run bulk commands' \
440 changelog:'generate a changelog report' \
441 chore:'create chore branch' \
442 clear-soft:'soft clean up a repository' \
443 clear:'rigorously clean up a repository' \
444 commits-since:'show commit logs since some date' \
445 contrib:'show user contributions' \
446 count:'show commit count' \
447 create-branch:'create branches' \
448 delete-branch:'delete branches' \
449 delete-merged-branches:'delete merged branches' \
450 delete-submodule:'delete submodules' \
451 delete-tag:'delete tags' \
452 delta:'lists changed files' \
453 effort:'show effort statistics on file(s)' \
454 extras:'awesome git utilities' \
455 feature:'create/merge feature branch' \
456 force-clone:'overwrite local repositories with clone' \
457 fork:'fork a repo on GitHub' \
458 fresh-branch:'create fresh branches' \
459 gh-pages:'create the GitHub pages branch' \
460 graft:'merge and destroy a given branch' \
461 guilt:'calculate change between two revisions' \
462 ignore-io:'get sample gitignore file' \
463 ignore:'add .gitignore patterns' \
464 info:'returns information on current repository' \
465 local-commits:'list local commits' \
466 lock:'lock a file excluded from version control' \
467 locked:'ls files that have been locked' \
468 merge-into:'merge one branch into another' \
469 merge-repo:'merge two repo histories' \
470 missing:'show commits missing from another branch' \
471 mr:'checks out a merge request locally' \
472 obliterate:'rewrite past commits to remove some files' \
473 pr:'checks out a pull request locally' \
474 psykorebase:'rebase a branch with a merge commit' \
475 pull-request:'create pull request to GitHub project' \
476 reauthor:'replace the author and/or committer identities in commits and tags' \
477 rebase-patch:'rebases a patch' \
478 refactor:'create refactor branch' \
479 release:'commit, tag and push changes to the repository' \
480 rename-branch:'rename a branch' \
481 rename-tag:'rename a tag' \
482 repl:'git read-eval-print-loop' \
483 reset-file:'reset one file' \
484 root:'show path of root' \
485 scp:'copy files to ssh compatible `git-remote`' \
486 sed:'replace patterns in git-controlled files' \
487 setup:'set up a git repository' \
488 show-merged-branches:'show merged branches' \
489 show-tree:'show branch tree of commit history' \
490 show-unmerged-branches:'show unmerged branches' \
491 squash:'import changes from a branch' \
492 stamp:'stamp the last commit message' \
493 standup:'recall the commit history' \
494 summary:'show repository summary' \
495 sync:'sync local branch with remote branch' \
496 touch:'touch and add file to the index' \
497 undo:'remove latest commits' \
498 unlock:'unlock a file excluded from version control'