1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2026-01-05 21:31:29 +01:00

users/19113: reorganised cryptsetup completion function

This commit is contained in:
Oliver Kiddle 2014-09-22 23:51:44 +02:00
parent 64e2b4426e
commit efffe080d5
2 changed files with 81 additions and 98 deletions

View file

@ -1,3 +1,7 @@
2014-09-22 Oliver Kiddle <opk@zsh.org>
* users/19113: Completion/Linux/_cryptsetup: reorganised function
2014-09-22 Daniel Hahler <dhahler@gmail.com>
* 33217: Functions/VCS_Info/Backends/VCS_INFO_get_data_git:

View file

@ -1,103 +1,82 @@
#compdef cryptsetup
## completion for cryptsetup 1.3.0, based on cryptsetup(1)
function _cryptsetup_action {
typeset -a 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
}
local curcontext="$curcontext" ret=1
local -a actions state line expl
function _cryptsetup_device {
typeset expl
_wanted file expl device \
_files
}
_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
function _cryptsetup_mapping {
typeset expl
_wanted file expl 'mapping name' \
_path_files -W /dev/mapper
}
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
function _cryptsetup_arguments {
case ${words[1]} in
create)
_arguments ':mapping:_cryptsetup_mapping' ':device:_cryptsetup_device'
;;
remove|status|resize|luksClose|luksSuspend|luksResume)
_arguments ': :_cryptsetup_mapping'
;;
luks(AddKey|RemoveKey|DelKey|UUID|Dump)|isLuks)
_arguments ': :_cryptsetup_device'
;;
luks(Format|AddKey|RemoveKey|ChangeKey))
_arguments ': :_cryptsetup_device' ':key file:_files'
;;
luksKillSlot)
_arguments ': :_cryptsetup_device' ':key slot number'
;;
luksOpen)
_arguments ': :_cryptsetup_device' ': :_cryptsetup_mapping'
;;
esac
}
function _cryptsetup {
_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]:bytes' \
'--new-keyfile-size[set new keyfile size (luksAddKey)]: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]: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]:milliseconds' \
'(-q --batch-mode)'{-q,--batch-mode}'[do not ask for confirmation]' \
'(-t --timeout)'{-t,--timeout}'[set password prompt timeout]:seconds' \
'(-T --tries)'{-T,--tries}'[set maximum number of retries]:maximum retries' \
'--align-payload[set payload alignment]:sectors' \
'--uuid[set device UUID]:uuid' \
'--version[show version information]' \
':action:_cryptsetup_action' \
'*::arguments:_cryptsetup_arguments'
}
_cryptsetup "$@"
return ret