about summary refs log tree commit diff
path: root/Completion/Unix/Command/_cdrdao
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Command/_cdrdao')
-rw-r--r--Completion/Unix/Command/_cdrdao246
1 files changed, 113 insertions, 133 deletions
diff --git a/Completion/Unix/Command/_cdrdao b/Completion/Unix/Command/_cdrdao
index 06b47c9b1..ad1bf4034 100644
--- a/Completion/Unix/Command/_cdrdao
+++ b/Completion/Unix/Command/_cdrdao
@@ -4,108 +4,85 @@
 
 # Command completion and main loop {{{1
 
-_cdrdao_commands () {
-  local -a commands
-
-  commands=(
-    'show-toc:print out a summary of a TOC'
-    'read-toc:create a TOC file based on a CD'
-    'read-cd:create a TOC file and image file based on a CD'
-    'read-cddb:add CD-TEXT data from a CDDB server to a TOC'
-    'show-data:print out samples that would be written to CD'
-    'read-test:check if data described in a TOC can be read from a CD'
-    'disk-info:show information about a CD'
-    'msinfo:generate mkisofs command for creating multi-session CD'
-    'unlock:try to unlock a recorder after a failed run'
-    'blank:blank a CD-RW'
-    'simulate:simulate a write'
-    'write:write a CD based on a TOC'
-    'copy:copy a CD'
-  )
-
-  _describe -t commands 'cdrdao command' commands && ret=0
-}
-
 _cdrdao () {
-  local curcontext=$curcontext ret=1
-
-  local context state line
-  typeset -A opt_args
-  _arguments \
-    ':command:->command' \
-    '*::options:->options' && ret=0
-  case $state in
-    (command)
-      _cdrdao_commands
-      ;;
-    (options)
-      curcontext="${curcontext%:*:*}:cdrdao-$words[1]:"
-      _call_function ret _cdrdao-$words[1]
-      ;;
-  esac
+  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 tmpfile_args
-tmpfile_args=(
+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]')
-
-declare -ga device_args
-device_args=(
-  '--device[set SCSI address of the CD recorder]:device:__cdrdao-device'
-  '--driver[use given driver for the CD recorder]:driver:__cdrdao-drivers')
+  '--keep[do not remove temporary data when done]'
+)
 
 # TODO: Gah!  Fix a cddb server spec matcher
-declare -ga cddb_args
-cddb_args=(
+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')
+  '--cddb-directory[directory where fetched CDDB records will be stored]:directory:_directories'
+)
 
-declare -g paranoiamode_arg=
-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_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 fasttoc_arg=
-fasttoc_arg='--fast-toc[skip pre-gap-length and index-mark extraction]'
+declare -g _cdrdao_fasttoc_arg
+_cdrdao_fasttoc_arg='--fast-toc[skip pre-gap-length and index-mark extraction]'
 
-declare -g swap_arg=
-swap_arg='--swap[swap the byte order of samples]'
+declare -g _cdrdao_swap_arg
+_cdrdao_swap_arg='--swap[swap the byte order of samples]'
 
-declare -g reload_arg=
-reload_arg='--reload[reload the disk if necessary]'
+declare -g _cdrdao_reload_arg
+_cdrdao_reload_arg='--reload[reload the disk if necessary]'
 
-declare -g eject_arg=
-eject_arg='--eject[eject CD after completed operation]'
+declare -g _cdrdao_eject_arg
+_cdrdao_eject_arg='--eject[eject CD after completed operation]'
 
-declare -g speed_arg=
-speed_arg='-speed[set writing speed]: :_guard "[[\:digit\:]]##" speed'
+declare -g _cdrdao_speed_arg
+_cdrdao_speed_arg='-speed[set writing speed]: :_guard "[[\:digit\:]]##" speed'
 
-declare -ga common_args
-common_args=(
+declare -ga _cdrdao_common_args
+_cdrdao_common_args=(
   '(*)'{-h,--help}'[display command/option summary]'
   '-v[set verbosity level]: :_guard "[[\:digit\:]]##" verbosity')
 
-declare -ga common_toc_args
-common_toc_args=(
-  $common_args
+declare -ga _cdrdao_common_toc_args
+_cdrdao_common_toc_args=(
+  $_cdrdao_common_args
   ':TOC file:_files -g "*.toc(-.)"')
 
-declare -ga common_device_args
-common_device_args=(
-  $common_args
-  $device_args)
-
-declare -ga common_toc_device_args
-common_toc_device_args=(
-  $common_toc_args
-  $common_device_args
-  $force_arg)
-
-declare -ga common_read_args
-common_read_args=(
+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"))'
@@ -128,18 +105,18 @@ _cdrdao-toc-size () {
 
 __cdrdao-show-toc-or-toc-info-or-toc-size () {
   _arguments \
-    $common_toc_args \
-    $tmpfile_args && ret=0
+    $_cdrdao_common_toc_args \
+    $_cdrdao_tmpfile_args
 }
 
 _cdrdao-read-toc () {
-  __cdrdao-read-toc-or-read-cd \
-    $fasttoc_arg
+  __cdrdao-read-toc-or-read-cd $_cdrdao_cddb_args
 }
 
 _cdrdao-read-cd () {
   __cdrdao-read-toc-or-read-cd \
-    $paranoiamode_arg
+    $_cdrdao_paranoiamode_arg \
+    $_cdrdao_cddb_args
 }
 
 __cdrdao-read-toc-or-read-cd () {
@@ -148,30 +125,31 @@ __cdrdao-read-toc-or-read-cd () {
   __cdrdao-read-toc-or-read-cd-or-copy-dependent-args
 
   _arguments \
-    $common_toc_device_args \
-    $common_read_args \
-    $dependent_args
+    $_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
+    "$@" && ret=0
 }
 
 _cdrdao-read-cddb () {
   _arguments \
-    $common_toc_args \
-    $cddb_args && ret=0
+    $_cdrdao_common_toc_args \
+    $_cdrdao_cddb_args
 }
 
 _cdrdao-show-data () {
   _arguments \
-    $common_toc_args \
-    $swap_arg && ret=0
+    $_cdrdao_common_toc_args \
+    $_cdrdao_swap_arg
 }
 
 _cdrdao-read-test () {
   _arguments \
-    $common_toc_args && ret=0
+    $_cdrdao_common_toc_args
 }
 
 _cdrdao-disk-info () {
@@ -180,13 +158,18 @@ _cdrdao-disk-info () {
 
 __cdrdao-disk-info-or-drive-info () {
   _arguments \
-    $common_device_args && ret=0
+    $_cdrdao_common_device_args
+}
+
+_cdrdao-discid() {
+  _arguments $_cdrdao_common_device_args $_cdrdao_cddb_args \
+    '--query-string[print out CDDB query only]'
 }
 
 _cdrdao-msinfo () {
   _arguments \
-    $common_device_args \
-    $reload_arg && ret=0
+    $_cdrdao_common_device_args \
+    $_cdrdao_reload_arg
 }
 
 _cdrdao-drive-info () {
@@ -195,22 +178,22 @@ _cdrdao-drive-info () {
 
 _cdrdao-unlock () {
   _arguments \
-    $common_device_args \
-    $reload_arg \
-    $eject_arg && ret=0
+    $_cdrdao_common_device_args \
+    $_cdrdao_reload_arg \
+    $_cdrdao_eject_arg
 }
 
 _cdrdao-blank () {
   _arguments \
-    $common_device_args \
-    $speed_arg \
+    $_cdrdao_common_device_args \
+    $_cdrdao_speed_arg \
     '--blank-mode[set the blanking mode]:blanking mode:(("full\:completely erase data" "minimal\:only dereference data"))' \
-    $eject_arg && ret=0
+    $_cdrdao_eject_arg
 }
 
 _cdrdao-scanbus () {
   _arguments \
-    $common_args && ret=0
+    $_cdrdao_common_args
 }
 
 _cdrdao-simulate () {
@@ -218,26 +201,26 @@ _cdrdao-simulate () {
 }
 
 __cdrdao-simulate-or-write () {
-  local capacity_arg=
-  
+  local _cdrdao_capacity_arg=
+
   if (( $words[(I)--full-burn] )); then
-    capacity_arg='--capacity[set disk capacity for --full-burn]: :_guard "[[\:digit\:]]" minutes'
+    _cdrdao_capacity_arg='--capacity[set disk capacity for --full-burn]: :_guard "[[\:digit\:]]" minutes'
   fi
 
   _arguments \
-    $common_toc_device_args \
-    $speed_arg \
+    $_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]' \
-    $capacity_arg \
-    $eject_arg \
-    $swap_arg \
+    $_cdrdao_capacity_arg \
+    $_cdrdao_eject_arg \
+    $_cdrdao_swap_arg \
     '--buffers[set fifo buffer size]: :_guard "[[\:digit\:]]" size' \
-    $reload_arg \
-    $tmpfile_args \
+    $_cdrdao_reload_arg \
+    $_cdrdao_tmpfile_args \
     '-n[do not pause before writing]' \
-    $* && ret=0
+    $*
 }
 
 _cdrdao-write () {
@@ -254,24 +237,24 @@ __cdrdao-read-toc-or-read-cd-or-copy-dependent-args () {
   fi
 
   if (( words[(I)--with-cddb] )); then
-    dependent_args+=$cddb_args
+    dependent_args+=$_cdrdao_cddb_args
   fi
 }
 
 _cdrdao-copy () {
-  local -ga dependent_args
+  local -a dependent_args
 
   __cdrdao-read-toc-or-read-cd-or-copy-dependent-args
 
   _cdrdao-write \
-    $dependent_args
-    $common_read_args
+    $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)]' \
-    $fasttoc_arg \
+    $_cdrdao_fasttoc_arg \
     '--keepimage[do not remove generated image when done]' \
-    $paranoiamode_arg && ret=0
+    $_cdrdao_paranoiamode_arg
 }
 
 # Type completion {{{1
@@ -280,24 +263,21 @@ __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)"}%% :*})
 
-  devices=(${(f)"$(_call_program devices cdrdao scanbus -v 0 2>/dev/null)"})
-  if (( ${#pipestatus:#0} > 0 )); then
-    return 1
-  fi
-
-  _wanted devices expl 'device' compadd - $devices
+  _wanted devices expl 'device' compadd -a devices
 }
 
 __cdrdao-drivers () {
-  local -a drivers
-
-  drivers=(${(f)"$(_call_program drivers cut -d'|' -f4 /usr/share/cdrdao/drivers -s 2>/dev/null | sort -u)"})
-  if (( ${#pipestatus:#0} > 0 )); then
-    return 1
+  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
-
-  _wanted drivers expl 'driver' compadd -qS: - $drivers
 }
 
 # }}}1