aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/gnupg.bash
blob: 8eac0439591b1d92d36065a4bc9c28c9b6f4114a (plain) (blame)
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
# Bail if no gpg(1)
if ! hash gpg 2>/dev/null; then
    return
fi

# Wrapper around gpg(1) to stop ``--batch'' breaking things
gpg() {
    case $* in
        *--ed*|*--gen-k*|*--sign-k*)
            command gpg --no-batch "$@"
            ;;
        *)
            command gpg "$@"
            ;;
    esac
}

# Completion for gpg with long options
_gpg() {
    local word=${COMP_WORDS[COMP_CWORD]}

    # Bail if word doesn't start with two dashes
    if [[ $word != --* ]]; then
        COMPREPLY=()
        return 1
    fi

    # Read options from the output of gpg --dump-options
    local -a options
    local option
    while read -r option; do
        options=("${options[@]}" "$option")
    done < <(gpg --dump-options 2>/dev/null)

    # Generate completion reply
    COMPREPLY=( $(compgen -W "${options[*]}" -- "$word") )
}
complete -F _gpg -o default gpg