diff options
Diffstat (limited to '')
-rw-r--r-- | completions/cryptsetup | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/completions/cryptsetup b/completions/cryptsetup index e73e165..9d23bfa 100644 --- a/completions/cryptsetup +++ b/completions/cryptsetup @@ -1,61 +1,52 @@ # bash completion for cryptsetup -*- shell-script -*- -_cryptsetup_name() +_comp_cmd_cryptsetup__name() { - COMPREPLY=($(compgen -X control -W '$(command ls /dev/mapper)' -- "$cur")) + _comp_compgen_split -X control -- "$(command ls /dev/mapper)" } -_cryptsetup_device() +_comp_cmd_cryptsetup__device() { - cur=${cur:=/dev/} - _filedir + _comp_compgen -c "${cur:-/dev/}" filedir } -_cryptsetup() +_comp_cmd_cryptsetup() { - local cur prev words cword split - _init_completion -s || return + local cur prev words cword was_split comp_args + _comp_initialize -s -- "$@" || return + local noargopts='!(-*|*[cslSbopitTdM]*)' + # shellcheck disable=SC2254 case $prev in --help | --version | --cipher | --hash | --*-size | --key-slot | --size | --offset | \ - --skip | --iter-time | --timeout | --tries | -!(-*)[chslSbopitT]) + --skip | --iter-time | --timeout | --tries | -${noargopts}[chslSbopitT]) return ;; - --key-file | --master-key-file | --header-backup-file | -!(-*)d) - _filedir + --key-file | --master-key-file | --header-backup-file | -${noargopts}d) + _comp_compgen_filedir return ;; - --type | -!(-*)M) - COMPREPLY=($(compgen -W "luks plain loopaes tcrypt" -- "$cur")) + --type | -${noargopts}M) + _comp_compgen -- -W "luks plain loopaes tcrypt" return ;; esac - $split && return + [[ $was_split ]] && return - local arg - _get_first_arg - if [[ -z $arg ]]; then - if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) - [[ ${COMPREPLY-} == *= ]] && compopt -o nospace - else - COMPREPLY=($(compgen -W 'open close resize status benchmark - repair erase luksFormat luksAddKey luksRemoveKey luksChangeKey - luksKillSlot luksUUID isLuks luksDump tcryptDump luksSuspend - luksResume luksHeaderBackup luksHeaderRestore' -- "$cur")) - fi - else - local args - _count_args "" "-!(-*)[chslSbopitTdM]" + local REPLY + if _comp_get_first_arg; then + local arg=$REPLY + _comp_count_args -a "-${noargopts}[chslSbopitTdM]" + local args=$REPLY case $arg in open | create | luksOpen | loopaesOpen | tcryptOpen) case $args in 2) - _cryptsetup_device + _comp_cmd_cryptsetup__device ;; 3) - _cryptsetup_name + _comp_cmd_cryptsetup__name ;; esac ;; @@ -63,31 +54,31 @@ _cryptsetup() luksSuspend | luksResume) case $args in 2) - _cryptsetup_name + _comp_cmd_cryptsetup__name ;; esac ;; luksFormat | luksAddKey | luksRemoveKey | luksChangeKey) case $args in 2) - _cryptsetup_device + _comp_cmd_cryptsetup__device ;; 3) - _filedir + _comp_compgen_filedir ;; esac ;; luksKillSlot | luksDelKey | luksUUID | isLuks | luksDump) case $args in 2) - _cryptsetup_device + _comp_cmd_cryptsetup__device ;; esac ;; luksHeaderBackup | luksHeaderRestore) case $args in 2) - _cryptsetup_device + _comp_cmd_cryptsetup__device ;; 3) COMPREPLY=('--header-backup-file') @@ -95,9 +86,19 @@ _cryptsetup() esac ;; esac + else + if [[ $cur == -* ]]; then + _comp_compgen_help + [[ ${COMPREPLY-} == *= ]] && compopt -o nospace + else + _comp_compgen -- -W 'open close resize status benchmark repair + erase luksFormat luksAddKey luksRemoveKey luksChangeKey + luksKillSlot luksUUID isLuks luksDump tcryptDump luksSuspend + luksResume luksHeaderBackup luksHeaderRestore' + fi fi } && - complete -F _cryptsetup cryptsetup + complete -F _comp_cmd_cryptsetup cryptsetup # ex: filetype=sh |