diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2013-10-16 17:43:55 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2013-10-16 17:43:55 +1300 |
commit | d59826be70e21e2890db2c9e85a23b3efda7edc5 (patch) | |
tree | ea7c053464193c63c433aa2f1cbba46651857f22 /bash | |
parent | Use default completion on empty COMPREPLY (diff) | |
download | dotfiles-d59826be70e21e2890db2c9e85a23b3efda7edc5.tar.gz dotfiles-d59826be70e21e2890db2c9e85a23b3efda7edc5.zip |
Add completion for GnuPG
Diffstat (limited to 'bash')
-rw-r--r-- | bash/bashrc.d/gnupg.bash | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bash/bashrc.d/gnupg.bash b/bash/bashrc.d/gnupg.bash new file mode 100644 index 00000000..0826be30 --- /dev/null +++ b/bash/bashrc.d/gnupg.bash @@ -0,0 +1,22 @@ +# Completion for gpg with long options +_gpg() { + local word=${COMP_WORDS[COMP_CWORD]} + + # Bail if no gpg(1) or the word doesn't start with two dashes + if ! hash gpg 2>/dev/null || [[ $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 + |