forked from np/git-annex-zsh-completion
-
Notifications
You must be signed in to change notification settings - Fork 6
/
_git-annex
398 lines (384 loc) · 17.1 KB
/
_git-annex
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#compdef git-annex
#description manage files while ignoring their content
# ZSH Completion for git-annex (http://git-annex.branchable.com/)
#
# This completion was written for git-annex version: 5.20140517
#
# Note that this completion is still very much early alpha work in progress.
#
# This completion depends on Python for a json parser, sorry. Unfortunately
# there is no such thing in zsh (yet).
#
# Skeleton implementation by Frank Terbeck <[email protected]>
# Blanks filled in by Valentin Haenel <[email protected]>
# Updated by Thomas Jost <[email protected]>
# Updated by Robin Schneider <[email protected]>
# Licence: WTFPL (http://sam.zoy.org/wtfpl/)
#
# To use this completion drop it somewhere in you $fpath, e.g.:
#
# $ git clone $CLONEURL
# $ fpath+=$PWD/git-annex-zsh-completion
# $ compinit git-annex
#
# TODO
# ----
#
# * 'git annex add' to only complete files not in annex
# * user defined groups are not detected
# * remotes with spaces in their description are not handled
#
local state line context
local -A opt_args
__annex_backend(){
local -a backends
backends=($(git annex version | awk -F': ' '/key\/value backends/ {print $2}'))
_describe -t backends backend backends
}
__annex_groups(){
local -a groups
groups=(client transfer backup incrementalbackup smallarchive archive source manual public unwanted)
_describe -t groups 'standard groups' groups
}
__annex_remotes(){
local -a remotes
remotes=($(git remote 2>/dev/null))
_describe -t remotes 'locally available remotes' remotes
}
__annex_repository(){
local -a currents
currents=('here')
_describe -t current current currents
__annex_remotes
local -a descriptions
descriptions=($(git annex info --fast --json 2>/dev/null |
python3 -c "
import json, re, shlex, sys
parsed = json.load(sys.stdin)
descriptions = []
for repo in (parsed['trusted repositories'] + parsed['semitrusted repositories'] + parsed['untrusted repositories']):
desc = repo['description']
m = re.match(r'(?:(.+?)\s*)?\[(.+)\]', desc)
if m is not None:
desc = m.group(2) + ('' if m.group(1) is None else (':' + m.group(1)))
descriptions.append(desc)
print(' '.join(descriptions))"))
_describe -t descriptions 'known remotes' descriptions
local -a uuids
uuids=($(git annex info --fast --json 2>/dev/null |
python3 -c "
import json, re, sys
parsed = json.load(sys.stdin)
uuids = []
for repo in (parsed['trusted repositories'] + parsed['semitrusted repositories'] + parsed['untrusted repositories']):
desc = repo['description']
m = re.match(r'(?:(?P<desc>.+?)\s*)?\[(?P<name>.+)\]', desc)
if m is not None:
desc = m.group(1) if m.group(1) is not None else m.group(2)
uuids.append('%s:%s' % (repo['uuid'], desc))
print(' '.join(uuids))"))
_describe -t uuids uuid uuids
}
local -a common_opts matching_opts
common_opts=(
'--force[allow actions that may lose annexed data]'
'(-F --fast)'{-F,--fast}'[avoid slow operations]'
'(-a --auto)'{-a,--auto}'[automatic mode]'
'--all[operate on all data, including old versions of files]'
'(-U --unused)'{-U,--unused}'[operate on all unused data]'
'(-k --key=)'{-k,--key=}'[specifies a key to operate on]:key'
'(-q --quiet)'{-q,--quiet}'[avoid verbose output]'
'(-v --verbose)'{-v,--verbose}'[allow verbose output (default)]'
'(-j --json)'{-j,--json}'[generate machine readable JSON]'
'(-d --debug)'{-d,--debug}'[show debug messages]'
'--no-debug[don''t show debug messages]'
'(-f --from=)'{-f,--from=}'[copy/move from repository]:repository:__annex_remotes'
'(-t --to=)'{-t,--to=}'[copy/move to repository]:repository:__annex_remotes'
'(-N --numcopies=)'{-N,--numcopies=}'[override default number of copies]: :_guard "[0-9]#" "number of copies"'
'(-T --time-limit=)'{-T,--time-limit=}'[stop after the specified amount of time]:time'
'--trust=[override trust setting]:repository:__annex_repository'
'--semitrust=[override trust setting back to default]:repository:__annex_repository'
'--untrust=[override trust setting to untrusted]:repository:__annex_repository'
'--trust-glacier-inventory[trust Amazon Glacier inventory]'
'(-b --backend=)'{-b,--backend=}'[specify key-value backend to use]:backend:__annex_backend'
'--format=[specifies a custom output format]:format'
'--user-agent=[override default User-Agent]:User-Agent'
'--notify-finish[show desktop notification after transfer finishes]'
'--notify-start[show desktop notification after transfer starts]'
'-c name=[override git configuration setting]:git configuration setting'
'--help[show help on a specific command]'
)
matching_opts=(
'(-x --exclude=)'{-x,--exclude=}'[skip files matching the glob pattern]:glob pattern'
'(-I --include=)'{-I,--include=}'[limit to files matching the glob pattern]:glob pattern'
'(-i --in=)'{-i,--in=}'[match files present in a remote]:repository:__annex_repository'
'(-C --copies=)'{-C,--copies=}'[skip files with fewer copies]: :_guard "[0-9]#" "number of copies"'
'--lackingcopies=[match files that need more copies]: :_guard "[0-9]#" "number of copies"'
'--approxlackingcopies=[match files that need more copies (faster)]: :_guard "[0-9]#" "number of copies"'
'(-B --inbackend=)'{-B,--inbackend=}'[match files using a key-value backend]:backend:__annex_backend'
'--inallgroup=[match files present in all remotes in a group]:group:__annex_groups'
'--smallerthan=[match files smaller than a size]:size'
'--largerthan=[match files larger than a size]:size'
'--metadata=[match files with attached metadata]:field=glob'
'--want-get[match files the repository wants to get]'
'--want-drop[match files the repository wants to drop]'
'--not[negate next option]'
'--and[both previous and next option must match]'
'--or[either previous or next option must match]'
'-\\([open group of options]'
'-\\)[close group of options]'
)
_arguments -C \
': :->command' \
'*:: :->subcmd'
case $state in
(command)
local -a common setup maintenance query metadata utility plumbing
common=(
add:'adds files in the path to the annex'
get:'makes the content of annexed files available in this repository'
drop:'drops the content of annexed files from this repository'
move:'move files from/to repositories'
copy:'copy from/to repositories'
unlock:'unlock a file for editing'
edit:'alias for the unlock command'
lock:'lock file again after editing'
sync:'synchronize with one or more remotes'
merge:'merge the git-annex branches of remotes'
mirror:'mirror a source repository to a destination repository'
addurl:'downloads each url to a file, which is added to the annex'
rmurl:'record that a file is no longer available at a url'
import:'move files from somewhere else and add them to the annex'
importfeed:'import the contents of podcast feeds'
watch:'watches for changes and automatically add files'
assistant:'like watch but automatically syncs changes to other remotes'
webapp:'runs a web app to setup and control the git-annex assistant'
)
setup=(
init:'initialize an annex'
describe:'changes the description of a repository'
initremote:'set up a special remote'
enableremote:'enable an existing special remote for use in the current repository'
numcopies:'tells git-annex how many copies it should preserve of files'
trust:'records that a repository is trusted to not unexpectedly lose content'
untrust:'records that a repository is not trusted and could lose content at any time'
semitrust:'returns a repository to the default semi trusted state'
dead:'Indicates that the repository has been irretrievably lost. (To undo, use semitrust.)'
group:'adds a repository to a group, such as "archival", "enduser", or "transfer"'
ungroup:'removes a repository from a group'
wanted:'display or configure the preferred content setting for a repository'
schedule:'display or configure scheduled jobs'
vicfg:'opens $EDITOR on a temp file containing most of the configuration settings'
direct:'switches a repository to use direct mode'
indirect:'switches a repository back from direct mode to the default, indirect mode'
)
maintenance=(
fsck:'check annex consistency'
unused:'check for data that has no symlinks pointing to it'
dropunused:'drop unused data, as reported by unused'
addunused:'adds back files listed by unused'
fix:'fix up symlinks that have become broken'
upgrade:'upgrades the repository to current layout'
forget:'rewrites the git-annex branch, throwing away historical data'
repair:'repairs many of the problem with git repositories'
)
query=(
find:'search for present/missing files in current annex'
whereis:'show all repositories that contain a file'
list:'displays a table of remotes that contain the contents of the specified files'
log:'displays the location log for the specified files'
info:'displays some statistics and other information'
version:'print version and repository information'
help:'print the most frequently used git-annex commands'
map:'generate a visual map of repositories'
)
metadata=(
metadata:'display or change metadata fields for the specified files'
view:'use metadata to build a view branch of the files in the current branch'
vpop:'switches from the currently active view back to the previous one'
vfilter:'filters the current view'
vadd:'adds an additional level of directories to categorize the files in the current view'
vcycle:'cycles the order of a view involving nested subdirectories'
)
utility=(
migrate:'migrate annexd files to new backend'
reinject:'moves a src file into the annex as the content of the dest file.'
unannex:'undo an accidental git annex add command'
uninit:'stop using git-annex entirely'
reinit:'reinit a repository, reusing its UUID'
)
plumbing=(
pre-commit:'fixes up symlinks that are staged as part of a commit'
lookupkey:'looks up the key used for a file in the index'
examinekey:'prints information that can be determined purely looking at a key'
fromkey:'set file to link to given key'
dropkey:'drop annexd data for specified keys'
transferkey:'request a single key to be transferred'
transferkeys:'internal command for the assistant'
rekey:'like migrate, but specifying both the file and its new key'
findref:'like find, but for a specific git ref instead of the current work tree'
test:'runs git-annex''s built-in test suite'
remotedaemon:'detects when network remotes have received git pushes and fetches from them'
xmppgit:'internal command to perform git pulls over XMPP'
fuzztest:'generates fuzz test files (developer tool)'
)
_describe -t common_commands "common commands" common
_describe -t setup_commands "setup commands" setup
_describe -t maintenance_commands "maintenance commands" maintenance
_describe -t query_commands "query commands" query
_describe -t metadata_commands "metadata commands" metadata
_describe -t utility_commands "utility commands" utility
_describe -t plumbing_commands "plumbing commands" plumbing
;;
(subcmd)
case ${line[1]} in
(direct|indirect|map|merge|repair|uninit|upgrade|vcycle|version|vicfg|vpop)
_message 'No more arguments'
;;
(dead|semitrust|trust|untrust)
__annex_repository
;;
(fix|reinject|unannex)
_path_files
;;
(unused)
_arguments $common_opts
;;
(add)
_arguments $common_opts $matching_opts \
'--include-dotfiles[include dotfiles that are not explicitly listed]' \
'*:path:_path_files'
;;
(addunused|dropunused)
_alternative $common_opts \
'range:Numbers:_guard "[0-9]#" "range of unused objects"' \
'all:all objects:(all)'
;;
(addurl)
_arguments $common_opts \
'--relaxed[don''t store the size of the url''s content]' \
'--pathdepth=[path depth to use for the file name]: :_guard "-#[0-9]#" "integer"' \
'--file=[destination file]:path:_path_files' \
'*:url:_urls'
;;
(assistant)
_arguments '--foreground[do not daemonize]' \
'--stop[stop the daemon]' \
'--autostart[start in known repositories]' \
'--startdelay=[delay before running startup scan]:delay'
;;
(describe)
_arguments ':repository:__annex_repository' \
':description:'
;;
(enableremote|initremote)
_arguments ':repository:__annex_repository' \
'*:param=value parameters:'
;;
(find)
_arguments $common_opts $matching_opts \
'--print0[output filenames terminated with nulls]' \
'*:path:_path_files'
;;
(forget)
_arguments '--drop-dead[prune references to dead repositories]'
;;
(fsck)
_arguments $common_opts $matching_opts\
'(-S --incremental)'{-S,--incremental}'[start an incremental fsck]' \
'(-m --more)'{-m,--more}'[continue an incremental fsck]' \
'--incremental-schedule=[schedule incremental fscking]:schedule expression' \
'*:path:_path_files'
;;
(group|ungroup)
_arguments ':repository:__annex_repository' \
':group name:__annex_groups'
;;
(help)
_arguments ':list common options:(options)'
;;
(import)
_arguments $common_opts \
'--duplicate[do not delete source files]' \
'--deduplicate[delete source files whose content was imported before]' \
'--clean-duplicates[delete duplicate source files (import nothing)]' \
'--skip-duplicates[import only new files]' \
'*:path:_path_files'
;;
(importfeed)
_arguments $common_opts \
'--template=[template for filenames]:template' \
'--relaxed[skip size check]' \
'*:feed url:_urls'
;;
(info)
_arguments $common_opts $matching_opts \
'*:directory:_path_files -/'
;;
(init|reinit)
_arguments '::description:'
;;
(list)
_arguments $common_opts $matching_opts \
'--allrepos[list all repositories]' \
'*:path:_path_files'
;;
(log)
_arguments $common_opts $matching_opts \
'--since=[show log since date]:since date' \
'--after=[show log after date]:after date' \
'--until=[show log until date]:until date' \
'--before=[show log before date]:before date' \
'(-n --max-count=)'{-m,--max-count}'[limit number of logs displayed]: :_guard "[0-9]#" "number of logs"' \
'--gource[generate output suitable for gource]' \
'*:path:_path_files'
;;
(metadata)
# No $common_opts: -t is for --tag, not --to.
_arguments $matching_opts \
'--all[operate on all versions of all files]' \
'(-k --key=)'{-k,--key=}'[operate on specified key]' \
'(-j --json)'{-j,--json}'[enable JSON output]' \
'(-U --unused)'{-U,--unused}'[operate on files found y last run of git-annex unused]' \
'(-s --set=)'{-s,--set}'[change a field value]:field=value' \
'(-g --get=)'{-g,--get}'[get a field value]:field' \
'(-t --tag=)'{-t,--tag}'[set a tag]:tag' \
'(-u --untag=)'{-u,--untag}'[remove a tag]:tag' \
'*:path:_path_files'
;;
(numcopies)
_arguments ': :_guard "[0-9]#" "number of copies"'
;;
(rmurl)
_arguments ':file:_files' \
':url:_urls'
;;
(schedule|wanted)
_arguments ':repository:__annex_repository' \
':epxression:'
;;
(sync)
_arguments $common_opts \
'--content[transfer annexed files contents]' \
'*:remote:__annex_remotes'
;;
(vadd|vfilter|view)
_message 'field=value, field=glob, field/=path, field!=value, /=path, tag, !tag'
;;
(vpop)
_arguments ': :_guard "[0-9]#" "number views to pop"'
;;
(watch)
_arguments '--foreground[do not daemonize]' \
'--stop[stop the daemon]'
;;
(webapp)
_arguments '--listen=[accept connections to this address]:address'
;;
(*)
_arguments $common_opts $matching_opts \
'*:path:_path_files'
;;
esac
;;
esac