Merge pull request #1387 from davvid/remote-dialog
[git-cola.git] / contrib / _git-cola
blobbf6df47ca3ca6170c67e07aa1f54aea1af998328
1 #compdef git-cola
2 #description zsh completion for git-cola
4 # The recommended way to install this script is to make a copy of it as a
5 # file named '_git-cola' inside any directory in your fpath.
7 # For example, create a directory '~/.config/zsh/completion',
8 # copy this file to '~/.config/zsh/completion/_git-cola',
9 # and then add the following to your ~/.zshrc file:
11 #  fpath=(~/.config/zsh/completion $fpath)
13 __git-cola_common_options () {
14         # these can't be prefixed
15         _arguments '--help[Show help]' \
16                 '--icon-theme=-[specify an icon theme name or directory]:theme:(dark light default)' \
17                 '--theme=-[specify a GUI theme name]:theme:(dark light default)' \
18                 '--prompt[prompt for a repository]' \
19                 '--repo=-[open the specified git repository]:repository:_files -/' \
20                 '--version[print version number]'
23 _git-cola_refs () {
24         typeset -a refs
25         local ref
27         if git rev-parse HEAD >/dev/null 2>&1
28         then
29                 for ref in $(git for-each-ref --format='%(refname:short)')
30                 do
31                         refs+=(${ref})
32                 done
34                 (( $#refs )) && _describe -t refs 'refs' refs
35         fi
39 _git-cola-am () {
40         __git-cola_common_options
41         _arguments \
42                 '*:patches:_files -g "*.patch"'
45 _git-cola-archive () {
46         __git-cola_common_options
47         _arguments \
48                 ':ref:_git-cola_refs'
51 _git-cola-cola () {
52         __git-cola_common_options
53         _arguments \
54                 '--status-filter=-[status path filter]:path:_files'
57 _git-cola-dag () {
58         __git-cola_common_options
59         _arguments \
60                 '--all[show all branches]' \
61                 '*:refs:_git-cola_refs'
64 _git-cola-diff () {
65         __git-cola_common_options
66         _arguments \
67                 '*:refs:_git-cola_refs'
70 _git-cola-find () {
71         __git-cola_common_options
72         _arguments \
73                 ':path:_files'
76 _git-cola-grep () {
77         __git-cola_common_options
78         _arguments \
79                 '*:path:_files'
82 _git-cola-merge () {
83         __git-cola_common_options
84         _arguments \
85                 ':ref:_git-cola_refs'
88 _git-cola-rebase () {
89         __git-cola_common_options
90         _arguments \
91                 '--autosquash[move commits that begin with squash!/fixup!]' \
92                 '--autostash[automatically stash/stash pop before and after]' \
93                 '--fork-point[use "merge-base --fork-point" to refine upstream]' \
94                 '--onto=-[rebase onto given branch instead of upstream]:ref:_git-cola_refs' \
95                 '--preserve-merges[try to recreate merges instead of ignoring them]' \
96                 '--root[rebase all reachable commits up to the root(s)]' \
97                 '--strategy=-[use the given merge strategy]:strategy:(recursive resolve octopus ort ours subtree)' \
98                 '--verify[allow pre-rebase hook to run]' \
99                 '--continue[continue]' \
100                 '--abort[abort adn check out the original branch]' \
101                 '--skip[skip current patch and continue]' \
102                 '--edit-todo[edit the todo list]' \
103                 ':ref:_git-cola_refs' \
104                 ':ref:_git-cola_refs'
107 _git-cola-tag () {
108         __git-cola_common_options
109         _arguments \
110                 '--sign[annotated and GPG-signed tag]' \
111                 ':tag name:' \
112                 ':ref:_git-cola_refs'
116 _git-cola () {
117         local curcontext="$curcontext" state line
118         typeset -A opt_args
119         _arguments -C \
120                 ':command:->command' \
121                 '*::options:->options' \
123         case $state in
124         (command)
125                 #breaks if defined outside the func
126                 local -a subcommands
127                 subcommands=(
128                         'about:about git-cola'
129                         'am:apply patches using "git am"'
130                         'archive:save an archive'
131                         'branch:create a branch'
132                         'browse:browse repository'
133                         'clone:clone repository'
134                         'cola:start git-cola'
135                         'config:edit configuration'
136                         'dag:visualize branch history'
137                         'diff:view diffs'
138                         'fetch:fetch remotes'
139                         'find:find files'
140                         'grep:grep source'
141                         'merge:merge branches'
142                         'pull:pull remote branches'
143                         'push:push remote branches'
144                         'rebase:interactive rebase'
145                         'recent:edit recent files'
146                         'remote:edit remotes'
147                         'search:search commits'
148                         'stash:stash and unstash changes'
149                         'tag:create tags'
150                         'version:print the version'
151                         '--help-commands:show available sub-commands'
152                 )
154                 _describe -t commands git-cola subcommands
155         ;;
156         (options)
157                 local funcname
158                 funcname=_git-cola-$line[1]
159                 if type $funcname | grep -q 'shell function'
160                 then
161                         $funcname
162                 else
163                         __git-cola_common_options
164                 fi
165         ;;
166         esac
169 _git-cola "$@"