forked from zsh-users/zsh-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_github
267 lines (254 loc) · 9.29 KB
/
_github
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#compdef github gh
# ------------------------------------------------------------------------------
# Copyright (c) 2011 Github zsh-users - https://github.com/zsh-users
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the zsh-users nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for Github gem 0.6.2 (https://github.com/defunkt/github-gem).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Julien Nicoulaud (https://github.com/nicoulaj)
#
# ------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------
_github() {
typeset -A opt_args
local context state line curcontext="$curcontext"
local ret=1
_arguments -C \
'1:cmd:->cmds' \
'*::arg:->args' \
&& ret=0
case "$state" in
(cmds)
local commands; commands=(
'admin:open this repo'\''s Admin panel a web browser'
'browse:open this repo in a web browser'
'clone:clone a repo'
'config:automatically set configuration info, or pass args to specify'
'create:create a new, empty GitHub repository'
'create-from-local:create a new GitHub repository from the current local repository'
'fetch:fetch from a remote to a local branch'
'fetch_all:fetch all refs from a user'
'fork:forks a GitHub repository'
'home:open this repo'\''s master branch in a web browser'
'ignore:ignore a SHA'
'info:info about this project'
'issues:project issues tools'
'network:project network tools'
'open:open the given user/project in a web browser'
'pull:pull from a remote'
'pull-request:generate the text for a pull request'
'search:search GitHub for the given repository name'
'track:track another user'\''s repository'
)
_describe -t commands 'command' commands && ret=0
;;
(args)
curcontext="${curcontext%:*:*}:github-cmd-$words[1]:"
case $words[1] in
(admin|fetch|fetch_all|home|info)
_message 'no more arguments' && ret=0
;;
(browse)
_arguments \
'1: :_github_users' \
'2: :_github_branches' \
&& ret=0
;;
(clone)
_arguments \
'1: :_github_users' \
'2: :_github_repos' \
'3: :_files -/' \
'--search[search for user or repo and clone selected repository]:user or repo' \
'--ssh[clone using the [email protected] style url]' \
&& ret=0
;;
(config)
_arguments \
'1: :_github_users' \
'2: :_github_repos' \
&& ret=0
;;
(create)
_arguments \
'1:repo name' \
'--markdown[create README.markdown]' \
'--mdown[create README.mdown]' \
'--private[create private repository]' \
'--rdoc[create README.rdoc]' \
'--rst[create README.rst]' \
'--textile[create README.textile]' \
&& ret=0
;;
(create-from-local)
_arguments \
'--private[create private repository]' \
&& ret=0
;;
(fork)
_arguments \
'1: :_github_user_slash_repos' \
&& ret=0
;;
(ignore)
_arguments \
'1: :_github_network_commits' \
&& ret=0
;;
(issues)
_arguments -C \
'1:issue-status:->issue-statuses' \
'2:: :_github_users' \
'--after[only show issues updated after a certain date]:date' \
'--label[only show issues with a certain label]:label' \
&& ret=0
case "$state" in
(issue-statuses)
local statuses; statuses=(
'open:show open issues'
'closed:show closed issues'
)
_describe -t statuses 'status' statuses && ret=0
;;
esac
;;
(network)
_arguments -C \
'1:network-subcommand:->network-subcommands' \
'*::network-arg:->network-args' \
'(--after)--before[only show commits before a certain date]:date' \
'(--before)--after[only show commits after a certain date]:date' \
'--applies[filter commits to patches that apply cleanly]' \
'--author[filter commits on a email address of author]:author' \
'--cache[use the network data even if it'\''s expired]' \
'--common[show common branch point]' \
'--limit[only look through the first X heads - useful for really large projects]:number' \
'--noapply[filter commits to patches that do not apply cleanly]' \
'--nocache[do not use the cached network data]' \
'--project[filter commits on a certain project]:project' \
'--shas[only show shas]' \
'--sort[how to sort : date, branch, author]:sort type:((date\:sort\ by\ date\ \(default\) branch\:sort\ by\ branch author\:sort\ by\ author))' \
'--thisbranch[look at branches that match the current one]' \
&& ret=0
case "$state" in
(network-subcommands)
local subcommands; subcommands=(
'web:open network in a web browser'
'list:list network members'
'fetch:fetch network members commits'
'commits:list network members commits'
)
_describe -t subcommands 'subcommand' subcommands && ret=0
;;
(network-args)
case $words[1] in
(web)
_arguments \
'1: :_github_users' \
&& ret=0
;;
esac
;;
esac
;;
(open)
_arguments \
'1: :_github_user_slash_repos' \
&& ret=0
;;
(pull)
_arguments \
'1: :_github_users' \
'2: :_github_branches' \
'--merge[automatically merge remote'\''s changes into your master]' \
&& ret=0
;;
(pull-request)
_arguments \
'1: :_github_users' \
'2: :_github_branches' \
&& ret=0
;;
(search)
_arguments \
'1:query' \
&& ret=0
;;
(track)
_arguments \
'1:: :((remote))' \
'*: :_github_user_slash_repos' \
{--private,--ssh}'[use [email protected]: instead of git://github.com/]' \
&& ret=0
;;
esac
;;
esac
return ret
}
(( $+functions[_github_users] )) ||
_github_users() {
_alternative \
'users:user:_users' \
'github-network-users:github network user:_github_network_users'
}
(( $+functions[_github_network_users] )) ||
_github_network_users() {
local users; users=(${(f)"$(_call_program users $service network list 2>/dev/null)"})
_describe -t github-network-users 'github network user' users "$@"
}
(( $+functions[_github_repos] )) ||
_github_repos() {
_message -e repos 'repo'
}
(( $+functions[_github_branches] )) ||
_github_branches() {
_message -e branches 'branch'
}
(( $+functions[_github_user_slash_repos] )) ||
_github_user_slash_repos() {
local ret=1
if compset -P '*/'; then
_wanted repos expl 'repo' _github_repos && ret=0
else
_wanted users expl 'user' _github_users -qS/ && ret=0
fi
return ret
}
(( $+functions[_github_network_commits] )) ||
_github_network_commits() {
local commits; commits=(${${(f)"$(_call_program commits $service network commits 2>/dev/null)"}%%[[:blank:]]*})
_describe -t commits 'commit' commits "$@"
}
_github "$@"