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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
#compdef moosic
_moosic_add_cmds() {
# querying for information
typeset -a queries
queries=(
"help:print brief description of command"
"current:print name of currently playing song"
"current-time:print the amount of time the current song has been playing"
"list:print the list of items in the current song queue"
"plainlist:print the current song queue without numbering each line"
"history:print a list of items that were recently played"
{status,state}":print the current state of the music daemon"
"length:print the number of items in the queue"
"ispaused:show whether the current song is paused or not"
"islooping:show whether the server is in loop mode"
"isadvancing:show whether the server is advancing through the song queue"
"version:print version information for client and server"
)
# appending to song queue
typeset -a appending
appending=(
{append,add}":add the files to be played to the end of the song queue"
{pl-append,pl-add}":add the items listed in the given playlist files to end of queue"
"prepend:add the files to be played to the beginning of the song queue"
"pl-prepend:add the items in the given playlist files to beginning of queue"
"mixin:add the files to the song queue and reshuffle the entire queue"
"pl-mixin:add items in given playlist files to song queue and reshuffle the entire queue"
"replace:replace the current contents of the song queue with files listed"
"pl-replace:replace current contents of song queue with songs given in playlists"
"insert:insert the given items at a given point in the song queue"
"pl-insert:insert items from playlist files at specified point in queue"
"putback:reinsert current song at start of song queue"
"stagger-add:adds file list to end of queue after rearranging queue into staggered order"
"stagger-merge:adds given file list to queue in interleaved fashion"
"interval-add:inserts given songs with regular frequency specified by interval argument"
)
# removing
typeset -a removing
removing=(
{cut,del}":removes all song queue items in given range"
"crop:removes all song queue items that do not fall within given range"
"remove:remove all song queue items matching any one of given regexps"
"filter:remove all queue items not matching all given regexps"
"clear:clear song queue"
"wipe:clear song queue and stop current song"
)
# rearranging
typeset -a rearranging
rearranging=(
"move:move all items in given range to new position in song queue"
"move-pattern:moves all items matching the given regexp to new position"
"swap:trade places of songs in two specified ranges"
{shuffle,reshuffle}":reshuffle song queue within an optional range"
"sort:sort queue within optional range"
"reverse:reverse order of song queue"
"partial-sort:sort items matching each regexp"
"stagger:stagger items matching each regexp"
"sub:perform regular expression substitution on all items in queue"
"suball:like sub, but replace all occurrences of the pattern"
)
# general management
typeset -a general
general=(
"next:jumps ahead, number of songs optional"
"previous:retreats to previously played song"
"goto:jumps to next song matching regexp"
"gobackto:jumps back to most recent previous song matching regexp"
"noadvance:halt queue advancement"
"advance:resume queue advancement"
"toggle-advance:toggle queue advancement"
"stop:stop playing current song, stop processing queue, put current song back"
"pause:suspend current song to resume it later"
"unpause:unpause current song"
"play:resume playing"
"loop:turn loop mode on"
"noloop:turn loop mode off"
"toggle-loop:toggle loop mode"
"reconfigure:daemon reload configuration file"
"showconfig:show daemon filetype associations"
"start-server:starts new instance of daemon with given options"
{quit,exit,die}":quit daemon"
)
_describe queries queries -J queries
_describe appending appending -J appending
_describe removing removing -J removing
_describe rearranging rearranging -J rearranging
_describe general general -J general
}
_moosic() {
typeset context state line
typeset -A opt_args
typeset -a filelist_opts
filelist_opts=(
'(-g --shuffle-global)'{-g,--shuffle-global}'[shuffle filelist after directory expansion]'
'(-d --shuffle-dir)'{-d,--shuffle-dir}'[shuffle results of expanding the directories]'
'(-a --shuffle-args)'{-a,--shuffle-args}'[shuffle actual command line arguments]'
'(-o --inorder)'{-o,--inorder}'[do not shuffle filelist]'
'(-s --sort)'{-s,--sort}'[sort filelist lexicographically after expansion]'
'(-r --no-recurse)'{-r,--no-recurse}'[do not recurse through directories]'
'(-n --no-file-munge)'{-n,--no-file-munge}'[do not modify names in expanded filelist]'
'(-f --auto-find)'{-f,--auto-find}'[perform fuzzy search for music files]'
'(-F --auto-grep)'{-F,--auto-grep}'[like --auto-find but with regexp]'
'(-U --allow-unplayable)'{-U,--allow-unplayable}'[allow addition of unknown song types]'
)
typeset -a auto_opts
auto_opts=(
'(-m --music-dir)'{-m,--music-dir}'[directory used for auto-find, auto-grep]:directory:_files'
)
typeset -a main_opts
main_opts=(
'(-i --ignore-case)'{-i,--ignore-case}'[treat regexps as if they are case-insensitive]'
'(-S --showcommands)'{-S,--showcommands}'[show all moosic commands, then exit]'
'(-h --help)'{-h,--help}'[print help message then exit]'
'(-v --version)'{-v,--version}'[print version information, then exit]'
'(-c --config-dir)'{-c,--config-dir}'[configuration directory]:directory:_files'
'(-t --tcp)'{-t,--tcp}'[talk to server at specified host and port]:host\:port:'
'(-N --no-startserver)'{-N,--no-startserver}'[do not start moosicd server]'
)
typeset -a list_opts
list_opts=(
'(-C --current-in-list)'{-C,--current-in-list}'[print currently playing song in list]'
)
# GLOBAL ARGUMENTS
# do not use the -A option here. It will break the processing of
# positional arguments.
_arguments $main_opts $list_opts $auto_opts $filelist_opts \
'1: :->cmd' \
'*:: :->posarg'
if [[ $state == cmd ]]; then
_moosic_add_cmds
elif [[ $state == posarg ]]; then
_moosic_cmd_${line[1]}
fi
}
# Do something, but only if the current word is 2.
_do2() {
if (( CURRENT == 2 )); then
$@
else
_message 'no more arguments'
fi
}
### QUERY COMMANDS
_moosic_cmd_help() {
_do2 '_moosic_add_cmds'
}
_moosic_cmd_current() {
_message 'no arguments'
}
_moosic_cmd_current-time() {
_do2 '_message' 'strftime string'
}
_moosic_cmd_list() {
_do2 '_message' 'range'
}
_moosic_cmd_plainlist() {
_do2 '_message' 'range'
}
_moosic_cmd_history() {
_do2 '_message' 'maximum number of entries'
}
_moosic_cmd_status() {
_message 'no arguments'
}
_moosic_cmd_state() {
_message 'no arguments'
}
_moosic_cmd_length() {
_message 'no arguments'
}
_moosic_cmd_ispaused() {
_message 'no arguments'
}
_moosic_cmd_islooping() {
_message 'no arguments'
}
_moosic_cmd_isadvancing() {
_message 'no arguments'
}
_moosic_cmd_version() {
_message 'no arguments'
}
### APPENDING COMMANDS
_moosic_song_files()
{
_arguments -A '-*' $main_opts $filelist_opts $auto_opts \
'*:song files:_files'
}
_moosic_cmd_append() {
_moosic_song_files
}
_moosic_cmd_add() {
_moosic_song_files
}
_moosic_cmd_pl-append() {
_moosic_song_files
}
_moosic_cmd_pl-add() {
_moosic_song_files
}
_moosic_cmd_prepend() {
_moosic_song_files
}
_moosic_cmd_pl-prepend() {
_moosic_song_files
}
_moosic_cmd_mixin() {
_moosic_song_files
}
_moosic_cmd_pl-mixin() {
_moosic_song_files
}
_moosic_cmd_replace() {
_moosic_song_files
}
_moosic_cmd_pl-replace() {
_moosic_song_files
}
_moosic_cmd_insert() {
_moosic_song_files
}
_moosic_cmd_pl-insert() {
_moosic_song_files
}
_moosic_cmd_putback() {
_message 'no arguments'
}
_moosic_cmd_stagger-add() {
_moosic_song_files
}
_moosic_cmd_stagger-merge() {
_moosic_song_files
}
_moosic_cmd_interval-add() {
_arguments -A '-*' $main_opts $filelist_opts \
'1:interval:' \
'*:song files:_files'
}
### REMOVING COMMANDS
_moosic_cmd_cut() {
_do2 '_message' 'range'
}
_moosic_cmd_del() {
_do2 '_message' 'range'
}
_moosic_cmd_crop() {
_do2 '_message' 'range'
}
_moosic_cmd_remove() {
_do2 '_message' 'regex'
}
_moosic_cmd_filter() {
_do2 '_message' 'regex'
}
_moosic_cmd_clear() {
_message 'no arguments'
}
_moosic_cmd_wipe() {
_message 'no arguments'
}
### REARRANGING COMMANDS
_moosic_cmd_move() {
_arguments -A '-*' $main_opts \
'1:range:' \
'2:index:' \
'*:no more arguments:'
}
_moosic_cmd_move-pattern() {
_arguments -A '-*' $main_opts \
'1:regex:' \
'2:index:' \
'*:no more arguments:'
}
_moosic_cmd_swap() {
_arguments -A '-*' $main_opts \
'1:range:' \
'2:range:' \
'*:no more arguments:'
}
_moosic_cmd_shuffle() {
_arguments -A '-*' $main_opts \
'1:range (optional):' \
'*:no more arguments:'
}
_moosic_cmd_reshuffle() {
_arguments -A '-*' $main_opts \
'1:range (optional):' \
'*:no more arguments:'
}
_moosic_cmd_sort() {
_arguments -A '-*' $main_opts \
'1:range (optional):' \
'*:no more arguments:'
}
_moosic_cmd_reverse() {
_arguments -A '-*' $main_opts \
'1:range (optional):' \
'*:no more arguments:'
}
_moosic_cmd_partial-sort() {
_do2 '_message' 'regex'
}
_moosic_cmd_stagger() {
_do2 '_message' 'regex'
}
_moosic_cmd_sub() {
_arguments -A '-*' $main_opts \
'1:pattern:' \
'2:replacement:' \
'3:range (optional):' \
'*:no more arguments:'
}
_moosic_cmd_suball() {
_arguments -A '-*' $main_opts \
'1:pattern:' \
'2:replacement:' \
'3:range (optional):' \
'*:no more arguments:'
}
### GENERAL COMMANDS
_moosic_cmd_next() {
if (( CURRENT == 2 )); then
typeset -a display display_cmd
if zstyle -a ":completion:${curcontext}:next" \
'command' display_cmd; then
$display_cmd
else
display=(${(f)"$(moosic list)"})
fi
typeset -a numbers
numbers=({1..${#display}})
compadd -V songs -d display -a numbers
else
_message 'no more arguments'
fi
}
_moosic_cmd_previous() {
_do2 '_message' 'number to skip'
}
_moosic_cmd_goto() {
_do2 '_message' 'regex'
}
_moosic_cmd_gobackto() {
_do2 '_message' 'regex'
}
_moosic_cmd_noadvance() {
_message 'no arguments'
}
_moosic_cmd_advance() {
_message 'no arguments'
}
_moosic_cmd_toggle-advance() {
_message 'no arguments'
}
_moosic_cmd_stop() {
_message 'no arguments'
}
_moosic_cmd_pause() {
_message 'no arguments'
}
_moosic_cmd_unpause() {
_message 'no arguments'
}
_moosic_cmd_play() {
_message 'no arguments'
}
_moosic_cmd_loop() {
_message 'no arguments'
}
_moosic_cmd_noloop() {
_message 'no arguments'
}
_moosic_cmd_toggle-loop() {
_message 'no arguments'
}
_moosic_cmd_reconfigure() {
_message 'no arguments'
}
_moosic_cmd_showconfig() {
_message 'no arguments'
}
_moosic_cmd_start-server() {
_message 'options'
}
_moosic_cmd_quit() {
_message 'no arguments'
}
_moosic_cmd_exit() {
_message 'no arguments'
}
_moosic_cmd_die() {
_message 'no arguments'
}
_moosic "$@"
|