summaryrefslogtreecommitdiffstats
path: root/completions/cryptsetup
blob: dbe2a2cd80cdba54fedaa185e4ecd5667468820f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# bash completion for cryptsetup                           -*- shell-script -*-

_comp_cmd_cryptsetup__name()
{
    _comp_compgen_split -X control -- "$(command ls /dev/mapper)"
}

_comp_cmd_cryptsetup__device()
{
    _comp_compgen -c "${cur:-/dev/}" filedir
}

_comp_cmd_cryptsetup()
{
    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 | -${noargopts}[chslSbopitT])
            return
            ;;
        --key-file | --master-key-file | --header | --header-backup-file | -${noargopts}d)
            _comp_compgen_filedir
            return
            ;;
        --type | -${noargopts}M)
            _comp_compgen -- -W "luks plain loopaes tcrypt"
            return
            ;;
    esac

    [[ $was_split ]] && return

    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)
                        _comp_cmd_cryptsetup__device
                        ;;
                    3)
                        _comp_cmd_cryptsetup__name
                        ;;
                esac
                ;;
            close | remove | luksClose | loopaesClose | tcryptClose | status | resize | \
                luksSuspend | luksResume)
                case $args in
                    2)
                        _comp_cmd_cryptsetup__name
                        ;;
                esac
                ;;
            luksFormat | luksAddKey | luksRemoveKey | luksChangeKey)
                case $args in
                    2)
                        _comp_cmd_cryptsetup__device
                        ;;
                    3)
                        _comp_compgen_filedir
                        ;;
                esac
                ;;
            luksKillSlot | luksDelKey | luksUUID | isLuks | luksDump)
                case $args in
                    2)
                        _comp_cmd_cryptsetup__device
                        ;;
                esac
                ;;
            luksHeaderBackup | luksHeaderRestore)
                case $args in
                    2)
                        _comp_cmd_cryptsetup__device
                        ;;
                    3)
                        COMPREPLY=('--header-backup-file')
                        ;;
                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 _comp_cmd_cryptsetup cryptsetup

# ex: filetype=sh