]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/git-extras/git-extras.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / git-extras / git-extras.plugin.zsh
1 # ------------------------------------------------------------------------------
2 # Description
3 # -----------
4 #
5 #  Completion script for git-extras (https://github.com/tj/git-extras).
6 #
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
9 #  with git.
10 #
11 # ------------------------------------------------------------------------------
12 # Authors
13 # -------
14 #
15 #  * Alexis GRIMALDI (https://github.com/agrimaldi)
16 #  * spacewander (https://github.com/spacewander)
17 #
18 # ------------------------------------------------------------------------------
19 # Inspirations
20 # -----------
21 #
22 #  * git-extras (https://github.com/tj/git-extras)
23 #  * git-flow-completion (https://github.com/bobthecow/git-flow-completion)
24 #
25 # ------------------------------------------------------------------------------
26
27
28 # Internal functions
29 # These are a lot like their __git_* equivalents inside _git
30
31 __gitex_command_successful () {
32   if (( ${#*:#0} > 0 )); then
33     _message 'not a git repository'
34     return 1
35   fi
36   return 0
37 }
38
39 __gitex_commits() {
40     declare -A commits
41     git log --oneline -15 | sed 's/\([[:alnum:]]\{7\}\) /\1:/' | while read commit
42     do
43         hash=$(echo $commit | cut -d':' -f1)
44         commits[$hash]="$commit"
45     done
46     local ret=1
47     _describe -t commits commit commits && ret=0
48 }
49
50 __gitex_remote_names() {
51     local expl
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
56 }
57
58 __gitex_tag_names() {
59     local expl
60     declare -a tag_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
64 }
65
66
67 __gitex_branch_names() {
68     local expl
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
73 }
74
75 __gitex_specific_branch_names() {
76     local expl
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
81 }
82
83 __gitex_chore_branch_names() {
84     __gitex_specific_branch_names 'chore'
85 }
86
87 __gitex_feature_branch_names() {
88     __gitex_specific_branch_names 'feature'
89 }
90
91 __gitex_refactor_branch_names() {
92     __gitex_specific_branch_names 'refactor'
93 }
94
95 __gitex_bug_branch_names() {
96     __gitex_specific_branch_names 'bug'
97 }
98
99 __gitex_submodule_names() {
100     local expl
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
105 }
106
107
108 __gitex_author_names() {
109     local expl
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
114 }
115
116 # subcommands
117 _git-authors() {
118     _arguments  -C \
119         '(--list -l)'{--list,-l}'[show authors]' \
120         '--no-email[without email]' \
121 }
122
123 _git-bug() {
124     local curcontext=$curcontext state line ret=1
125     declare -A opt_args
126
127     _arguments -C \
128         ': :->command' \
129         '*:: :->option-or-argument' && ret=0
130
131     case $state in
132         (command)
133             declare -a commands
134             commands=(
135                 'finish:merge bug into the current branch'
136             )
137             _describe -t commands command commands && ret=0
138             ;;
139         (option-or-argument)
140             curcontext=${curcontext%:*}-$line[1]:
141             case $line[1] in
142                 (finish)
143                     _arguments -C \
144                         ':branch-name:__gitex_bug_branch_names'
145                     ;;
146                 -r|--remote )
147                     _arguments -C \
148                         ':remote-name:__gitex_remote_names'
149                     ;;
150             esac
151             return 0
152     esac
153
154     _arguments \
155         '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
156 }
157
158
159 _git-changelog() {
160     _arguments \
161         '(-l --list)'{-l,--list}'[list commits]' \
162 }
163
164 _git-chore() {
165     local curcontext=$curcontext state line ret=1
166     declare -A opt_args
167
168     _arguments -C \
169         ': :->command' \
170         '*:: :->option-or-argument' && ret=0
171
172     case $state in
173         (command)
174             declare -a commands
175             commands=(
176                 'finish:merge and delete the chore branch'
177             )
178             _describe -t commands command commands && ret=0
179             ;;
180         (option-or-argument)
181             curcontext=${curcontext%:*}-$line[1]:
182             case $line[1] in
183                 (finish)
184                     _arguments -C \
185                         ':branch-name:__gitex_chore_branch_names'
186                     ;;
187                 -r|--remote )
188                     _arguments -C \
189                         ':remote-name:__gitex_remote_names'
190                     ;;
191             esac
192             return 0
193     esac
194
195     _arguments \
196         '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
197 }
198
199
200 _git-contrib() {
201     _arguments \
202         ':author:__gitex_author_names'
203 }
204
205
206 _git-count() {
207     _arguments \
208         '--all[detailed commit count]'
209 }
210
211 _git-create-branch() {
212     local curcontext=$curcontext state line
213     _arguments -C \
214         ': :->command' \
215         '*:: :->option-or-argument'
216
217     case "$state" in
218         (command)
219             _arguments \
220                 '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
221             ;;
222         (option-or-argument)
223             curcontext=${curcontext%:*}-$line[1]:
224             case $line[1] in
225                 -r|--remote )
226                     _arguments -C \
227                         ':remote-name:__gitex_remote_names'
228                     ;;
229             esac
230     esac
231 }
232
233 _git-delete-branch() {
234     _arguments \
235         ':branch-name:__gitex_branch_names'
236 }
237
238
239 _git-delete-submodule() {
240     _arguments \
241         ':submodule-name:__gitex_submodule_names'
242 }
243
244
245 _git-delete-tag() {
246     _arguments \
247         ':tag-name:__gitex_tag_names'
248 }
249
250
251 _git-effort() {
252     _arguments \
253         '--above[ignore file with less than x commits]'
254 }
255
256
257 _git-extras() {
258     local curcontext=$curcontext state line ret=1
259     declare -A opt_args
260
261     _arguments -C \
262         ': :->command' \
263         '*:: :->option-or-argument' && ret=0
264
265     case $state in
266         (command)
267             declare -a commands
268             commands=(
269                 'update:update git-extras'
270             )
271             _describe -t commands command commands && ret=0
272             ;;
273     esac
274
275     _arguments \
276         '(-v --version)'{-v,--version}'[show current version]'
277 }
278
279
280 _git-feature() {
281     local curcontext=$curcontext state line ret=1
282     declare -A opt_args
283
284     _arguments -C \
285         ': :->command' \
286         '*:: :->option-or-argument' && ret=0
287
288     case $state in
289         (command)
290             declare -a commands
291             commands=(
292                 'finish:merge feature into the current branch'
293             )
294             _describe -t commands command commands && ret=0
295             ;;
296         (option-or-argument)
297             curcontext=${curcontext%:*}-$line[1]:
298             case $line[1] in
299                 (finish)
300                     _arguments -C \
301                         ':branch-name:__gitex_feature_branch_names'
302                     ;;
303                 -r|--remote )
304                     _arguments -C \
305                         ':remote-name:__gitex_remote_names'
306                     ;;
307             esac
308             return 0
309     esac
310
311     _arguments \
312         '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
313 }
314
315 _git-graft() {
316     _arguments \
317         ':src-branch-name:__gitex_branch_names' \
318         ':dest-branch-name:__gitex_branch_names'
319 }
320
321 _git-guilt() {
322     _arguments -C \
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]'
327 }
328
329 _git-ignore() {
330     _arguments  -C \
331         '(--local -l)'{--local,-l}'[show local gitignore]' \
332         '(--global -g)'{--global,-g}'[show global gitignore]' \
333         '(--private -p)'{--private,-p}'[show repo gitignore]'
334 }
335
336
337 _git-ignore() {
338     _arguments  -C \
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]'
344 }
345
346
347 _git-merge-into() {
348     _arguments '--ff-only[merge only fast-forward]'
349     _arguments \
350         ':src:__gitex_branch_names' \
351         ':dest:__gitex_branch_names'
352 }
353
354 _git-missing() {
355     _arguments \
356         ':first-branch-name:__gitex_branch_names' \
357         ':second-branch-name:__gitex_branch_names'
358 }
359
360
361 _git-refactor() {
362     local curcontext=$curcontext state line ret=1
363     declare -A opt_args
364
365     _arguments -C \
366         ': :->command' \
367         '*:: :->option-or-argument' && ret=0
368
369     case $state in
370         (command)
371             declare -a commands
372             commands=(
373                 'finish:merge refactor into the current branch'
374             )
375             _describe -t commands command commands && ret=0
376             ;;
377         (option-or-argument)
378             curcontext=${curcontext%:*}-$line[1]:
379             case $line[1] in
380                 (finish)
381                     _arguments -C \
382                         ':branch-name:__gitex_refactor_branch_names'
383                     ;;
384                 -r|--remote )
385                     _arguments -C \
386                         ':remote-name:__gitex_remote_names'
387                     ;;
388             esac
389             return 0
390     esac
391
392     _arguments \
393         '(--remote -r)'{--remote,-r}'[setup remote tracking branch]'
394 }
395
396
397 _git-squash() {
398     _arguments \
399         ':branch-name:__gitex_branch_names'
400 }
401
402 _git-stamp() {
403     _arguments  -C \
404          '(--replace -r)'{--replace,-r}'[replace stamps with same id]'
405 }
406
407 _git-standup() {
408     _arguments -C \
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]'
417 }
418
419 _git-summary() {
420     _arguments '--line[summarize with lines rather than commits]'
421     __gitex_commits
422 }
423
424
425 _git-undo(){
426     _arguments  -C \
427         '(--soft -s)'{--soft,-s}'[only rolls back the commit but changes remain un-staged]' \
428         '(--hard -h)'{--hard,-h}'[wipes your commit(s)]'
429 }
430
431 zstyle -g existing_user_commands ':completion:*:*:git:*' user-commands
432
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'