From d59826be70e21e2890db2c9e85a23b3efda7edc5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 16 Oct 2013 17:43:55 +1300 Subject: Add completion for GnuPG --- .gitignore | 1 + bash/bashrc.d/gnupg.bash | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 bash/bashrc.d/gnupg.bash diff --git a/.gitignore b/.gitignore index 40f82fb4..37fa884a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ bash/bashrc.d/* !bash/bashrc.d/ed.bash !bash/bashrc.d/ftp.bash !bash/bashrc.d/grep.bash +!bash/bashrc.d/gnupg.bash !bash/bashrc.d/ls.bash !bash/bashrc.d/mysql.bash !bash/bashrc.d/options.bash 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 + -- cgit v1.2.3