aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/gpg.bash
blob: 28c5b722ca02098064327177bf301750473eb255 (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
# Wrapper around gpg(1) to stop ``--batch'' breaking things
gpg() {
    # shellcheck disable=SC2048
    case $* in
        *--ed*|*--gen-k*|*--sign-k*)
            set -- --no-batch "$@"
            ;;
    esac
    command gpg "$@"
}

# Completion for gpg with long options
_gpg() {

    # Bail if no gpg(1)
    hash gpg 2>/dev/null || return 1

    # Bail if not completing an option
    [[ ${COMP_WORDS[COMP_CWORD]} == --* ]] || return 1

    # Generate completion reply from gpg(1) options
    local option
    while read -r option ; do
        [[ $option == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
        COMPREPLY[${#COMPREPLY[@]}]=$option
    done < <(gpg --dump-options 2>/dev/null)
}
complete -F _gpg -o default gpg