# bash completion for cryptsetup -*- shell-script -*- proc _cryptsetup_name { setglobal COMPREPLY = '( '$( compgen -X control -W '$( command ls /dev/mapper )' \ -- "$cur" ) ) } proc _cryptsetup_device { setglobal cur = $(cur:=/dev/) _filedir } proc _cryptsetup { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with --key-file|--master-key-file|--header-backup-file|-d _filedir return 0 } $split && return var arg = '' _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace } else { setglobal COMPREPLY = '( '$( compgen -W 'create remove status resize luksFormat luksOpen luksClose luksSuspend luksResume luksAddKey luksRemoveKey luksKillSlot luksDelKey luksUUID isLuks luksDump luksHeaderBackup luksHeaderRestore' -- "$cur" ) ) } } else { var args = '' _count_args match $arg { with create match $args { with 2 _cryptsetup_name with 3 _cryptsetup_device } with remove|status|resize|luksClose|luksSuspend|luksResume match $args { with 2 _cryptsetup_name } with luksFormat|luksAddKey|luksRemoveKey match $args { with 2 _cryptsetup_device with 3 _filedir } with luksOpen match $args { with 2 _cryptsetup_device with 3 _cryptsetup_name } with luksKillSlot|luksDelKey|luksUUID|isLuks|luksDump match $args { with 2 _cryptsetup_device } with luksHeaderBackup|luksHeaderRestore match $args { with 2 _cryptsetup_device with 3 setglobal COMPREPLY = '( ''--header-backup-file' ) } } } return 0 } && complete -F _cryptsetup cryptsetup # ex: ts=4 sw=4 et filetype=sh