forked from illusori/bash-itunes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitunes
executable file
·773 lines (680 loc) · 21.8 KB
/
itunes
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
#!/bin/bash
#
# A simple command-line wrapper for Apple's iTunes.
#
# Install or symlink into your path and "itunes -h" or "itunes help" for help.
#
# Copyright 2012 Sam Graham. http://www.illusori.co.uk/
# This work is licensed under a
# Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License
# http://creativecommons.org/licenses/by-sa/2.0/uk/
# In human-readble terms: you're free to copy, distribute and modify
# providing you maintain attribution and licence.
#
# Use at your own risk, no fitness for purpose implied, etc, etc.
version='1.2.2'
progname=`basename $0`
config_dir="$HOME/.bash-itunes"
plugins_dir="$config_dir/plugins"
# Version and help.
function _cmd_version() {
echo "$progname version $version"
}
function _cmd_help() {
_cmd_version
echo "Usage: $progname [-v] [-h] [-d] <command> [<args>]
Switches:
-v Show version information and exit.
-h Show this help and exit.
-d Enable debug messages, additional -d options increase verbosity.
Navigation commands:
play Resume playing or choose track.
pause Pause playing.
stop Stop playing.
next Skip to next track.
prev Skip back to previous track.
info View info about current track.
search Search for tracks.
shuffle View or set shuffle status.
repeat View or set repeat status.
playlist View or choose playlist.
playlists List all playlists.
Volume commands:
vol[ume] View or adjust iTunes volume 'up', 'down' or percentage.
mute Mutes iTunes.
unmute Unmutes iTunes, restoring previous volume level.
sysvol[ume] View or adjust system volume 'up', 'down' or percentage.
sysmute Mute system sound.
sysunmute Unmute system sound.
Application commands:
open Start iTunes running.
quit Quit iTunes.
show Hide the iTunes window.
hide Show the iTunes window.
Additional commands:
version Show version information and exit.
help Show this help and exit.
plugins Show a list of plugins installed."
}
function _cmd_unknown() {
echo "Unknown command '$cmd', try '$progname help' for a list of valid commands."
}
# Helper functions
function _err() {
echo "$*" 1>&2
}
function _log() {
if [ "$debug" -ge "$1" ]; then
shift;
_err "$*"
fi
}
function _pluralize() {
if [ "$1" = "1" ]; then
echo "$1 $2"
else
if [ -n "$3" ]; then
echo "$1 $3"
else
echo "$1 ${2}s"
fi
fi
}
function _quote_for_applescript_string() {
local value="$*"
value="${value//\\/\\\\}"
value="${value//\"/\\\"}"
_log 4 "Escaping '$*' to '$value' for use in applescript string"
echo "$value"
}
function _osascript() {
_log 2 "Run: osascript -e \"$*\""
if [ "$debug" -gt 0 ]; then
osascript -e "$*"
else
osascript -e "$*" 2>&-
fi
}
function _tell_itunes() {
_osascript "tell application \"iTunes\" to $*"
}
function _ask_itunes() {
_osascript "tell application \"iTunes\"
$*
set AppleScript's text item delimiters to \"\\n\"
ret as text
end tell"
}
# Fetch from iTunes from the data-structures in $1 into the array
# variables constructed from prefix $2 and column names $3+ the
# given columns in the data-structure.
# If that's clear.
# No?
# Anyone?
function _fetch_from_itunes() {
local source="$1"
local use_loop=0
if [ "$source" = "LOOP" ]; then
use_loop=1
source="$2"
shift
fi
local prefix="$2"
shift 2
# Yet more hacks, this allows multi-word AppleScript properties
# such as "database id" to end up in "database_id".
# You can also do this by messing with $IFS and ${var//search/replace}
# but, although I got it working, I had a brief outbreak of sanity and
# chose this instead...
local columns=''
local script_columns=''
for column in "$@"; do
columns="${columns} ${column// /_}"
script_columns="${script_columns}, ${column}"
done
columns="${columns:1}"
script_columns="${script_columns:2}"
_log 4 "source '$structure', prefix '$prefix', columns '$columns', script_columns '$script_columns'"
# Best if we don't loop within AppleScript, it can be painfully slow
# for large arrays, but on the other hand, for columns that are
# actually expressions rather than properties, we appear to have to loop.
if [ "$use_loop" = 0 ]; then
local result=$(_ask_itunes "set ret to ($script_columns) of $source")
_log 4 "result '$result'"
_read_rows_from_value_lines_grouped_by_column "$prefix" "$result" $columns
else
local result=$(_ask_itunes "set ret to {}
repeat with v in $source as list
copy ($script_columns) of v to the end of ret
end repeat")
_log 4 "result '$result'"
_read_rows_from_value_lines "$prefix" "$result" $columns
fi
}
# Low-level row/rowset fetching/clearing. This stuff is nasty.
# This function is lifted from my bash-snippets repo on GitHub,
# gawp in horror at its unspeakable glory.
function _read_rows_from_value_lines_grouped_by_column() {
local prefix="$1"
local content="$2"
shift 2
local columns
read -r -a columns <<< "$*"
local row_count=$(($(wc -l <<< "$content") / ${#columns[*]}))
for column in "${columns[@]}"; do
unset "${prefix}_${column}"
done
local row_idx=0
local column_idx=0
local value
while read value; do
column=${columns[column_idx]}
# Ho hum, I gave up and used eval, couldn't get this working with $(())
printf -v value "%q" "$value"
eval "${prefix}_${column}[${row_idx}]=$value"
row_idx=$((row_idx + 1))
if [ "$row_idx" -ge "$row_count" ]; then
row_idx=0
column_idx=$((column_idx + 1))
fi
#_log 5 "Column is $column, column_idx now $column_idx, row_idx now $row_idx, value $value"
done <<< "$content"
}
function _read_rows_from_value_lines() {
local prefix="$1"
local content="$2"
shift 2
local columns
read -r -a columns <<< "$*"
for column in "${columns[@]}"; do
#echo "Scrubbing ${prefix}_${column}"
unset "${prefix}_${column}"
done
local row_idx=0
local column_idx=0
local value
while read value; do
column=${columns[column_idx]}
# Ho hum, I gave up and used eval, couldn't get this working with $(())
printf -v value "%q" "$value"
eval "${prefix}_${column}[${row_idx}]=$value"
column_idx=$((column_idx + 1))
if [ "$column_idx" -ge "${#columns[*]}" ]; then
column_idx=0
row_idx=$((row_idx + 1))
fi
#_log 5 "Column is $column, column_idx now $column_idx, row_idx now $row_idx"
done <<< "$content"
}
function _scrub_rows() {
local prefix="$1"
shift
local columns="$@"
for column in $columns; do
local full_column="${prefix}_${column}"
_log 6 "Scrubbing \$$full_column"
unset $full_column
done
}
# Schema stuff.
_track_columns="name artist album year rating time id"
_playlist_columns="name time id"
# Fetchers/scrubbers for the objects in the schema.
function _fetch_tracks() {
_fetch_from_itunes "$@" $_track_columns
}
function _scrub_tracks() {
local prefix="$1"
_scrub_rows "$prefix" $_track_columns
}
function _fetch_playlists() {
local source="$1"
local prefix="$2"
_fetch_from_itunes "$@" $_playlist_columns
_fetch_from_itunes LOOP "$source" "$prefix" "count tracks"
}
function _scrub_playlists() {
local prefix="$1"
_scrub_rows "$prefix" $_playlist_columns
_scrub_rows "$prefix" count_tracks
}
# Fetchers/scrubbers for specific global objects.
function _fetch_current_track() {
if [ -z "$current_track_name" ]; then
_fetch_tracks "current track" current_track
fi
if [ -z "$current_track_pos" ]; then
current_track_pos=$(_tell_itunes "player position as integer")
local min=$((current_track_pos / 60))
local sec=$(printf "%02d" $((current_track_pos % 60)))
current_track_pos="${min}:${sec}"
_log 3 "Fetched trackpos '$current_track_pos'"
fi
}
function _scrub_current_track() {
_scrub_tracks "current_track"
unset "current_track_pos"
}
function _fetch_current_playlist() {
if [ -z "$current_playlist_name" ]; then
_fetch_playlists "current playlist" current_playlist
fi
}
function _scrub_current_playlist() {
_scrub_playlists "current_playlist"
}
# Views.
function _show_track() {
local row_prefix="$1"
local row_idx="${2:-0}"
local brief="${3:-0}"
local preamble="$4"
# Ho ho.
eval "local name=\${${row_prefix}_name[row_idx]}"
eval "local artist=\${${row_prefix}_artist[row_idx]}"
eval "local album=\${${row_prefix}_album[row_idx]}"
eval "local year=\${${row_prefix}_year[row_idx]}"
eval "local rating=\${${row_prefix}_rating[row_idx]}"
eval "local time=\${${row_prefix}_time[row_idx]}"
eval "local id=\${${row_prefix}_id[row_idx]}"
if [ -n "$preamble" ]; then
preamble="$preamble "
fi
echo -n "$preamble\"$name\""
if [ -n "$artist" ]; then
echo " by $artist"
fi
if [ -n "$album" ]; then
echo -n "\"$album\""
if [ -n "$year" -a "$year" != 0 ]; then
echo " ($year)"
fi
fi
if [ -n "$current_track_id" -a -n "$current_track_pos" -a "$current_track_id" = "$id" ]; then
echo " ($current_track_pos of $time)"
else
echo " ($time)"
fi
if [ "$brief" = 0 -a -n "$rating" -a "$rating" != 0 ]; then
echo "You've rated this track $rating."
fi
}
function _show_current_track() {
local preamble="$1"
local brief="${2:-0}"
_fetch_current_track
_show_track current_track 0 $brief "$preamble"
}
function _show_tracks() {
local prefix="$1"
local brief="${2:-0}"
local track_idx=0
eval "local track_name=\${${prefix}_name[track_idx]}"
eval "local track_id=\${${prefix}_id[track_idx]}"
while [ -n "$track_name" ]; do
if [ "$current_track_id" = "$track_id" ]; then
echo -n "* "
else
echo -n " "
fi
_show_track $prefix $track_idx $brief
track_idx=$((track_idx + 1))
eval "track_name=\${${prefix}_name[track_idx]}"
eval "track_id=\${${prefix}_id[track_idx]}"
done
}
function _show_playlist() {
local row_prefix="$1"
local row_idx="${2:-0}"
local brief="${3:-0}"
local preamble="$4"
# Ho ho.
eval "local name=\${${row_prefix}_name[row_idx]}"
eval "local time=\${${row_prefix}_time[row_idx]}"
eval "local id=\${${row_prefix}_id[row_idx]}"
eval "local count_tracks=\${${row_prefix}_count_tracks[row_idx]}"
if [ -n "$preamble" ]; then
preamble="$preamble "
fi
echo -n "$preamble\"${name}\" (${time}) ("
echo -n $(_pluralize "${count_tracks}" 'track')
echo -n ")"
if [ "$brief" = 0 ]; then
echo ":"
_show_tracks "${row_prefix}_tracks" 1
else
echo
fi
}
function _show_current_playlist() {
local preamble="$1"
local brief="${2:-0}"
_fetch_current_track
_fetch_current_playlist
_fetch_tracks "every track of current playlist" current_playlist_tracks
_show_playlist current_playlist 0 $brief "$preamble"
}
# Navigation commands: play, pause, stop, next, prev, playlist
function _cmd_play() {
if [ -z "$*" ]; then
_tell_itunes "play"
_scrub_current_track
_show_current_track "Resuming" 1
else
_tell_itunes "play item 1 of ((tracks of current playlist whose name is \"$*\") & (tracks of current playlist whose name contains \"$*\") & (tracks whose name is \"$*\") & (tracks whose name contains \"$*\"))"
_scrub_current_track
_show_current_track "Now playing" 1
fi
}
function _cmd_pause() {
echo "Pausing iTunes."
_tell_itunes "pause"
}
function _cmd_stop() {
echo "Stopping iTunes."
_tell_itunes "stop"
}
function _cmd_next() {
_tell_itunes "next track"
_scrub_current_track
_show_current_track "Skipping to next track," 1
}
function _cmd_prev() {
_tell_itunes "previous track"
_scrub_current_track
_show_current_track "Skipping to previous track," 1
}
function _cmd_info() {
if [ -z "$*" ]; then
_cmd_info_track
else
local cmd="$1"
shift
case "$cmd" in
track)
_cmd_info_track "$@"
;;
playlist)
_cmd_info_playlist "$@"
;;
esac
fi
}
function _cmd_info_track() {
if [ -z "$*" ]; then
_show_current_track "Currently playing"
else
_fetch_tracks "track \"$*\"" track
_show_track track 0 0
fi
}
function _cmd_info_playlist() {
if [ -z "$*" ]; then
_show_current_playlist "Currently listening to playlist" 0
else
_fetch_playlists "playlist \"$*\"" playlist
_fetch_tracks "every track of playlist \"$*\"" playlist_tracks
_show_playlist playlist 0 0
fi
}
function _cmd_search() {
if [ -z "$*" ]; then
_err "Usage: $progname search [<all | track | albumn | artist >] <search term>"
else
local target
local desc
case "$1" in
track | tracks | song | songs)
target='songs'; desc='name'; shift ;;
album | albums) target='albums'; desc='album title'; shift ;;
artist | artists) target='artists'; desc='artist'; shift ;;
all) target='all'; desc='anything'; shift ;;
*) target='all' desc='anything' ;;
esac
local search_term="$*"
local escaped_search_term=$(_quote_for_applescript_string "$search_term")
_fetch_tracks LOOP "(search playlist \"Library\" for \"$escaped_search_term\" only $target)" search_tracks
echo "Searching for tracks with $desc containing \"$search_term\":"
_show_tracks "search_tracks" 1
fi
}
function _cmd_shuffle() {
if [ -z "$1" ]; then
curshuffle=$(_tell_itunes "shuffle of current playlist")
_log 3 "Fetched shuffle is '$curshuffle'"
if [ "$curshuffle" = "true" ]; then
echo "Current shuffle setting is on."
else
echo "Current shuffle setting is off."
fi
else
case "$1" in
"on")
echo "Switching shuffle on."
_tell_itunes "set shuffle of current playlist to true"
;;
"off")
echo "Switching shuffle off."
_tell_itunes "set shuffle of current playlist to false"
;;
*)
_err "Shuffle must be one of 'on' or 'off'."
;;
esac
fi
}
function _cmd_repeat() {
if [ -z "$1" ]; then
currepeat=$(_tell_itunes "song repeat of current playlist")
_log 3 "Fetched repeat is '$currepeat'"
echo "Current repeat setting is $currepeat."
else
case "$1" in
"off" | "one" | "all")
echo "Switching repeat to $1."
_tell_itunes "set song repeat of current playlist to $1"
;;
*)
_err "Repeat must be one of 'one', 'all' or 'off'."
;;
esac
fi
}
function _cmd_playlist() {
if [ -z "$1" ]; then
_cmd_info_playlist
else
_tell_itunes "play item 1 of ((playlists whose name is \"$*\") & (playlists whose name contains \"$*\"))"
_scrub_current_track
_scrub_current_playlist
_fetch_current_playlist
_show_current_track "Now listening to playlist \"${current_playlist_name}\" (${current_playlist_time}), playing" 1
fi
}
function _cmd_playlists() {
_fetch_playlists "playlists" playlist
echo "Playlists"
local playlist_idx=0
while [ -n "${playlist_name[playlist_idx]}" ]; do
_show_playlist playlist $playlist_idx 1 " "
playlist_idx=$((playlist_idx + 1))
done
}
# Volume commands: volume, mute, unmute
function _cmd_volume() {
curvol=$(_tell_itunes "sound volume as integer")
_log 3 "Fetched volume is '$curvol'"
if [ -z "$1" ]; then
echo "Current iTunes volume is $curvol%"
else
newvol=-1
case "$1" in
"up") newvol=$(($curvol + 10)) ;;
"down") newvol=$(($curvol - 10)) ;;
"mute") _cmd_mute ;;
"unmute") _cmd_unmute ;;
*)
if [ "$1" -ge 0 -a "$1" -le 100 2>&- ] ; then
newvol=$1
else
_err "Volume must be one of 'up', 'down', 'mute', 'unmute' or an integer between 0 and 100."
fi
;;
esac
if [ $newvol != -1 ]; then
echo "Changing iTunes volume level from $curvol to $newvol%"
_tell_itunes "set sound volume to $newvol"
fi
fi
}
function _cmd_mute() {
echo "Muting iTunes."
_tell_itunes "set mute to true"
}
function _cmd_unmute() {
echo "Unmuting iTunes."
_tell_itunes "set mute to false"
}
# Not strictly iTunes, but likely to be useful anyway.
function _cmd_sysvolume() {
curvol=$(_osascript "output volume of (get volume settings)")
_log 3 "Fetched volume is '$curvol'"
if [ -z "$1" ]; then
echo "Current system volume is $curvol%"
else
newvol=-1
case "$1" in
"up") newvol=$(($curvol + 10)) ;;
"down") newvol=$(($curvol - 10)) ;;
"mute") _cmd_sysmute ;;
"unmute") _cmd_sysunmute ;;
*)
if [ "$1" -ge 0 -a "$1" -le 100 2>&- ] ; then
newvol=$1
else
_err "Volume must be one of 'up', 'down', 'mute', 'unmute' or an integer between 0 and 100."
fi
;;
esac
if [ $newvol != -1 ]; then
echo "Changing system volume level from $curvol to $newvol%"
_osascript "set volume output volume $newvol"
fi
fi
}
function _cmd_sysmute() {
echo "Muting system sound."
_osascript "set volume output muted true"
}
function _cmd_sysunmute() {
echo "Unmuting system sound."
_osascript "set volume output muted false"
}
# Application commands: open, quit
function _cmd_open() {
echo "Opening iTunes."
open -a iTunes
}
function _cmd_quit() {
echo "Quitting iTunes."
_tell_itunes "quit"
}
function _cmd_show() {
echo "Showing iTunes window."
_osascript "tell application \"System Events\" to set visible of process \"iTunes\" to true"
}
function _cmd_hide() {
echo "Hiding iTunes window."
_osascript "tell application \"System Events\" to set visible of process \"iTunes\" to false"
}
function _cmd_plugins() {
echo "Installed plugins:"
local glob="$plugins_dir/*"
local plugins=($glob)
if [ -z "$plugins" -o "$plugins" = "$glob" ]; then
echo " No plugins installed."
else
for plugin in $plugins; do
local plugin_cmd=`basename $plugin`
echo -n " $plugin_cmd - "
if [ -f "$plugin" ]; then
. "$plugin"
if [ -z "$PLUGIN_NAME" ]; then
PLUGIN_NAME="Missing PLUGIN_NAME"
fi
if [ -z "$PLUGIN_VERSION" ]; then
PLUGIN_VERSION="Missing PLUGIN_VERSION"
fi
if [ -z "$PLUGIN_BRIEF" ]; then
PLUGIN_BRIEF="Missing PLUGIN_BRIEF"
fi
echo "$PLUGIN_NAME ($PLUGIN_VERSION)"
echo " $PLUGIN_BRIEF"
unset PLUGIN_NAME
unset PLUGIN_VERSION
unset PLUGIN_BRIEF
else
echo "Not a plugin file"
fi
done
fi
}
# Argument processing and dispatch
function _dispatch() {
cmd=$1
shift
case "$cmd" in
# Navigation commands.
play|resume|unpause)
_cmd_play "$@" ;;
pause) _cmd_pause "$@" ;;
stop) _cmd_stop "$@" ;;
next) _cmd_next "$@" ;;
prev) _cmd_prev "$@" ;;
info) _cmd_info "$@" ;;
search) _cmd_search "$@" ;;
shuffle) _cmd_shuffle "$@" ;;
repeat) _cmd_repeat "$@" ;;
playlist) _cmd_playlist "$@" ;;
playlists) _cmd_playlists "$@" ;;
# Volume commands.
vol|volume) _cmd_volume "$@" ;;
mute) _cmd_mute "$@" ;;
unmute) _cmd_unmute "$@" ;;
sysvol|sysvolume)
_cmd_sysvolume "$@" ;;
sysmute) _cmd_sysmute "$@" ;;
sysunmute) _cmd_sysunmute "$@" ;;
# Application commands.
open) _cmd_open "$@" ;;
quit) _cmd_quit "$@" ;;
show|reveal) _cmd_show "$@" ;;
hide) _cmd_hide "$@" ;;
# Extra commands.
version) _cmd_version "$@" ;;
""|help) _cmd_help "$@" ;;
plugins) _cmd_plugins "$@" ;;
*)
if [ -f "$plugins_dir/$cmd" ]; then
. "$plugins_dir/$cmd"
_cmd_$cmd "$@"
else
_cmd_unknown "$@"
fi
;;
esac
}
debug=0
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
# Being run directly, do our command processing.
while getopts "hvd" "OPTNAME"; do
case $OPTNAME in
h) _cmd_help; exit 0 ;;
v) _cmd_version; exit 0 ;;
d) debug=$(($debug + 1)) ;;
*) exit -1 ;;
esac
done
shift $(($OPTIND - 1))
_dispatch "$@"
fi