about summary refs log tree commit diff
path: root/Completion/Unix/Command/_cdrdao
blob: ad1bf403439997738e88e357bab4ed4d7e2f2a2a (plain) (blame)
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
#compdef cdrdao

# TODO: Options must come before parameters.

# Command completion and main loop {{{1

_cdrdao () {
  local ret=1
  local -a commands
  if (( CURRENT == 2 )); then
    commands=( ${${${(M)${(f)"$(_call_program subcommands cdrdao 2>&1)"}:#  *}// #- /:}#??} )
    _describe -t subcommands 'cdrdao command' commands && ret=0
  else
    local cmd="${words[2]}"
    local curcontext="${curcontext%:*:*}:cdrdao-$cmd:"
    shift words
    (( CURRENT-- ))
    if ! _call_function ret _cdrdao-$cmd; then
      _default && ret=0
    fi
  fi

  return ret
}

# Common arguments {{{1

declare -ga _cdrdao_tmpfile_args
_cdrdao_tmpfile_args=(
  '--tmpdir[directory to store temporary data in]:directory:_directories'
  '--keep[do not remove temporary data when done]'
)

# TODO: Gah!  Fix a cddb server spec matcher
declare -ga _cdrdao_cddb_args
_cdrdao_cddb_args=(
  '--cddb-servers[specify list of CDDB servers to use]:CDDB servers:'
  '--cddb-timeout[specify timeout in seconds for connections to CDDB servers]: :_guard "[[\:digit\:]]" timeout'
  '--cddb-directory[directory where fetched CDDB records will be stored]:directory:_directories'
)

declare -g _cdrdao_paranoiamode_arg
_cdrdao_paranoiamode_arg='--paranoia-mode[set correction mode for digital audio extraction]:mode:(("0\:no checking" "1\:perform overlapped reading to avoid jitter" "2\:like 1 but with checks of read audio data" "3\:like 2 but with scratch detection/repair (default)"))'

declare -g _cdrdao_fasttoc_arg
_cdrdao_fasttoc_arg='--fast-toc[skip pre-gap-length and index-mark extraction]'

declare -g _cdrdao_swap_arg
_cdrdao_swap_arg='--swap[swap the byte order of samples]'

declare -g _cdrdao_reload_arg
_cdrdao_reload_arg='--reload[reload the disk if necessary]'

declare -g _cdrdao_eject_arg
_cdrdao_eject_arg='--eject[eject CD after completed operation]'

declare -g _cdrdao_speed_arg
_cdrdao_speed_arg='-speed[set writing speed]: :_guard "[[\:digit\:]]##" speed'

declare -ga _cdrdao_common_args
_cdrdao_common_args=(
  '(*)'{-h,--help}'[display command/option summary]'
  '-v[set verbosity level]: :_guard "[[\:digit\:]]##" verbosity')

declare -ga _cdrdao_common_toc_args
_cdrdao_common_toc_args=(
  $_cdrdao_common_args
  ':TOC file:_files -g "*.toc(-.)"')

declare -ga _cdrdao_common_device_args
_cdrdao_common_device_args=(
  $_cdrdao_common_args
  '--device[set SCSI address of the CD recorder]:device:__cdrdao-device'
  '--driver[use given driver for the CD recorder]:driver:__cdrdao-drivers'
)

declare -ga _cdrdao_common_toc_device_args
_cdrdao_common_toc_device_args=(
  $_cdrdao_common_toc_args
  $_cdrdao_common_device_args
  '--force[force execution of operation]'
)

declare -ga _cdrdao_common_read_args
_cdrdao_common_read_args=(
  '--rspeed[set reading speed]: :_guard "[[\:digit\:]]##" speed'
  '--session[specify what session to process on multi-session CDs]: :_guard "[[\:digit\:]]##" "session number"'
  '--read-subchan[set sub-channel reading-mode]:mode:(("rw\:de-interleaved and error corrected" "rw_raw\:not de-interleaved, not error-corrected, and L-EC data included"))'
  '--tao-source[indicate that source CD was written in TAO mode]'
  '--with-cddb[retrieve CD-TEXT data from a CDDB server]')

# Sub-command completion {{{1

_cdrdao-show-toc () {
  __cdrdao-show-toc-or-toc-info-or-toc-size
}

_cdrdao-toc-info () {
  __cdrdao-show-toc-or-toc-info-or-toc-size
}

_cdrdao-toc-size () {
  __cdrdao-show-toc-or-toc-info-or-toc-size
}

__cdrdao-show-toc-or-toc-info-or-toc-size () {
  _arguments \
    $_cdrdao_common_toc_args \
    $_cdrdao_tmpfile_args
}

_cdrdao-read-toc () {
  __cdrdao-read-toc-or-read-cd $_cdrdao_cddb_args
}

_cdrdao-read-cd () {
  __cdrdao-read-toc-or-read-cd \
    $_cdrdao_paranoiamode_arg \
    $_cdrdao_cddb_args
}

__cdrdao-read-toc-or-read-cd () {
  local -a dependent_args

  __cdrdao-read-toc-or-read-cd-or-copy-dependent-args

  _arguments \
    $_cdrdao_common_toc_device_args \
    $_cdrdao_common_read_args \
    $dependent_args \
    $_cdrdao_fasttoc_arg \
    '--datafile[set name of data file placed in TOC file]:file:_files' \
    '--read-raw[read data in raw format from CD]' \
    '--no-mode2-mixed[if MODE2_FORM1 or MODE2_FORM2, do not extract as MODE2_FORM_MIX]' \
    "$@" && ret=0
}

_cdrdao-read-cddb () {
  _arguments \
    $_cdrdao_common_toc_args \
    $_cdrdao_cddb_args
}

_cdrdao-show-data () {
  _arguments \
    $_cdrdao_common_toc_args \
    $_cdrdao_swap_arg
}

_cdrdao-read-test () {
  _arguments \
    $_cdrdao_common_toc_args
}

_cdrdao-disk-info () {
  __cdrdao-disk-info-or-drive-info
}

__cdrdao-disk-info-or-drive-info () {
  _arguments \
    $_cdrdao_common_device_args
}

_cdrdao-discid() {
  _arguments $_cdrdao_common_device_args $_cdrdao_cddb_args \
    '--query-string[print out CDDB query only]'
}

_cdrdao-msinfo () {
  _arguments \
    $_cdrdao_common_device_args \
    $_cdrdao_reload_arg
}

_cdrdao-drive-info () {
  __cdrdao-disk-info-or-drive-info
}

_cdrdao-unlock () {
  _arguments \
    $_cdrdao_common_device_args \
    $_cdrdao_reload_arg \
    $_cdrdao_eject_arg
}

_cdrdao-blank () {
  _arguments \
    $_cdrdao_common_device_args \
    $_cdrdao_speed_arg \
    '--blank-mode[set the blanking mode]:blanking mode:(("full\:completely erase data" "minimal\:only dereference data"))' \
    $_cdrdao_eject_arg
}

_cdrdao-scanbus () {
  _arguments \
    $_cdrdao_common_args
}

_cdrdao-simulate () {
  __cdrdao-simulate-or-write
}

__cdrdao-simulate-or-write () {
  local _cdrdao_capacity_arg=

  if (( $words[(I)--full-burn] )); then
    _cdrdao_capacity_arg='--capacity[set disk capacity for --full-burn]: :_guard "[[\:digit\:]]" minutes'
  fi

  _arguments \
    $_cdrdao_common_toc_device_args \
    $_cdrdao_speed_arg \
    '--multi[do not close the session after successful write]' \
    '--overburn[allow overburing of medium]' \
    '--full-burn[force burning to the outer disk edge]' \
    $_cdrdao_capacity_arg \
    $_cdrdao_eject_arg \
    $_cdrdao_swap_arg \
    '--buffers[set fifo buffer size]: :_guard "[[\:digit\:]]" size' \
    $_cdrdao_reload_arg \
    $_cdrdao_tmpfile_args \
    '-n[do not pause before writing]' \
    $*
}

_cdrdao-write () {
  __cdrdao-simulate-or-write \
    '--simulate[only perform a write simulation]' \
    '--buffer-under-run-protection[whether to use buffer under-run protection]:buffer under-run protection setting:(("0\:disable buffer under-run protection" "1\:enable buffer under-run protection"))' \
    '--write-speed-control[whether to use writing-speed control]:writing-speed control setting:(("0\:disable writing-speed control" "1\:enable writing-speed control"))' \
    $*
}

__cdrdao-read-toc-or-read-cd-or-copy-dependent-args () {
  if (( words[(I)--tao-source] )); then
    dependent_args+='--tao-source-adjust[specify number of link blocks for tracks written in TAO mode]: :_guard "[[\:digit\:]]##" "link blocks"'
  fi

  if (( words[(I)--with-cddb] )); then
    dependent_args+=$_cdrdao_cddb_args
  fi
}

_cdrdao-copy () {
  local -a dependent_args

  __cdrdao-read-toc-or-read-cd-or-copy-dependent-args

  _cdrdao-write \
    $dependent_args \
    $_cdrdao_common_read_args \
    '--source-device[set SCSI address of the CD reader]:device:__cdrdao-device' \
    '--source-driver[use given driver for the CD reader]:driver:__cdrdao-drivers' \
    '--on-the-fly[perform on-the-fly copy of CD (no image created)]' \
    $_cdrdao_fasttoc_arg \
    '--keepimage[do not remove generated image when done]' \
    $_cdrdao_paranoiamode_arg
}

# Type completion {{{1

__cdrdao-device () {
  # Use cdrdao scanbus and also check what OS we're running under and provide
  # additional stuff, like devices (/dev/sg0)
  local -a devices
  devices=(${${(f)"$(_call_program devices cdrdao scanbus -v 0 2>&1)"}%% :*})

  _wanted devices expl 'device' compadd -a devices
}

__cdrdao-drivers () {
  local suf
  local -Ua drivers
  drivers=(${(f)"$(_call_program drivers cut -d'\|' -f4 /usr/share/cdrdao/drivers -s)"})
  if compset -P \*:; then
    _message -e options option
  else
    compset -S :\* || suf=-qS:
    _wanted drivers expl 'driver' compadd $suf -a drivers
  fi
}

# }}}1

_cdrdao