Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: rsync --progress stops completion



Bart wrote:
> >
> While trying out a few completion functions that use repeated calls to
> _arguments, I encountered some miscellaneous bugs (I didn't try enough
> functions to pretend this is even close to all the bugs that may be
> lurking):
> 
> _cryptsetup - offers all options when completing after "-", but will
>  only allow one option to appear on the command line, as if all options
>  are mutually exclusive.

I can't reproduce this. There's obvious issues like not declaring some
things local, return values, etc. I've attached a reorganised function
that still calls _arguments twice. Does it also exhibit the problem?

> _quilt - returns 0 even when it finds no completions, breaking the
>  zstyle fallback I suggested.

Not difficult to fix but I suspect it's not the only function with that
issue.

> _bzr - complains to stderr if bzr is not in $path
> _surfraw - complains to stderr if surfraw is not in $path
> 
> The latter two make me think that _call_program should do something
> with stderr -- probably just throw it away, rather than make every
> caller add its own redirection.

Note that a significant number of programs send their --help output to
stderr. They're easily identified by searching for 2>& if the functions
need adjusting to avoid breaking them. _call_program could throw away
stderr unless something like -e is passed. But should -e imply 2>&1?
The advantage of an explicit 2>/dev/null is everyone knows what it does
without checking the manual.

Oliver

#compdef cryptsetup

local curcontext="$curcontext" ret=1
local -a actions state line expl

_arguments \
  '(-v --verbose)'{-v,--verbose}'[enable verbose mode]' \
  '--debug[enable debug mode]' \
  '(-h --hash)'{-h,--hash}'[hash algorithm]:hash algorithm' \
  '(-c --cipher)'{-c,--cipher}'[set cipher]:cipher specification' \
  '(-y --verify-passphrase)'{-y,--verify-passphrase}'[query for password twice]' \
  '(-d --key-file)'{-d,--key-file}'[set keyfile]:key file:_files' \
  '(-l --keyfile-size)'{-l,--keyfile-size}'[set keyfile size]:size (bytes)' \
  '--new-keyfile-size[set new keyfile size (luksAddKey)]:size (bytes)' \
  '--master-key-file[set master key]:key file:_files' \
  '--dump-master-key[dump luks master key]' \
  '(--use-urandom)--use-random[use /dev/random to generate volume key]' \
  '(--use-random)--use-urandom[use /dev/urandom to generate volume key]' \
  '(-S --key-slot)'{-S,--key-slot}'[select key slot]:key slot' \
  '(-s --key-size)'{-s,--key-size}'[set key size]:size (bits)' \
  '(-b --size)'{-b,--size}'[force device size]:sectors' \
  '(-o --offset)'{-o,--offset}'[set start offset]:sectors' \
  '(-p --skip)'{-p,--skip}'[data to skip at beginning]:sectors' \
  '--readonly[set up read-only mapping]' \
  '(-i --iter-time)'{-i,--iter-time}'[set password processing duration]:duration (milliseconds)' \
  '(-q --batch-mode)'{-q,--batch-mode}'[do not ask for confirmation]' \
  '(-t --timeout)'{-t,--timeout}'[set password prompt timeout]:timeout (seconds)' \
  '(-T --tries)'{-T,--tries}'[set maximum number of retries]:number of retries' \
  '--align-payload[set payload alignment]:sectors' \
  '--uuid[set device UUID]:uuid' \
  '(- : *)--version[show version information]' \
  ':action:->actions' \
  '*::arguments:->action-arguments' && ret=0

case $state in
  actions)
    actions=(
      'create:create a mapping'
      'remove:remove an existing mapping'
      'status:report mapping status'
      'resize:resize an active mapping'
      'luksFormat:initialize a LUKS partition'
      'luksOpen:open LUKS partition'
      'luksClose:remove an existing mapping'
      'luksSuspend:suspend active device'
      'luksResume:resume suspended device'
      'luksAddKey:add a new key'
      'luksRemoveKey:remove a key'
      'luksChangeKey:change a key'
      'luksKillSlot:wipe key from slot'
      'luksUUID:print/change device UUID'
      'isLuks:check if device is a LUKS partition'
      'luksDump:dump header information'
      'luksHeaderBackup:store binary backup of headers'
      'luksHeaderRestore:restore header backup'
    )
    _describe action actions && ret=0
  ;;
  action-arguments)
    local -a args
    local mapping=':mapping:_path_files -W /dev/mapper'
    local device=':device:_files'
    case ${words[1]} in
      create) args=( $mapping $device );;
      luksKillSlot) args=( $device ':key slot number' );;
      luksOpen) args=( $device $mapping );;
      remove|status|resize|luksClose|luksSuspend|luksResume) args=( $mapping );;
      luks(AddKey|RemoveKey|DelKey|UUID|Dump)|isLuks) args=( $device );;
      luks(Format|AddKey|RemoveKey|ChangeKey))
	args=( $device ':key file:_files' )
      ;;
      luksHeader*) args=( $device '--header-backup-file:file:_files' );;
      *)
        _default
	return
      ;;
    esac
    _arguments $args && ret=0
  ;;
esac

return ret


Messages sorted by: Reverse Date, Date, Thread, Author