diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-10-21 13:08:09 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-10-21 13:08:09 +1300 |
commit | dcfc80aaa112498498d93bae3ae0eb2088244c47 (patch) | |
tree | 889854ba1c96f1c86465da1bbd5cc87f0c8d4b9f /bash/bashrc.d/gpg.bash | |
parent | Handle spaces correctly in completions (diff) | |
download | dotfiles-dcfc80aaa112498498d93bae3ae0eb2088244c47.tar.gz dotfiles-dcfc80aaa112498498d93bae3ae0eb2088244c47.zip |
Tidy up completion considerably; no more compgen
* Remove all instances of compgen; for filename completion it's quite
broken as it relies on implicit wordsplitting in array context, and
doesn't have an option to print with a null delimiter; replaced with
manual for/while loops instead
* Add IFS= to while/read loops over filenames
* Use "dirname/s" instead of "dir/s" variables to avoid keyword
collisions and for clarity
* Remove some unnecessary variables
* Use shorter syntax for loop exit conditions
* Move completion options into functions where applicable rather than
having them on the completion definition itself
Diffstat (limited to 'bash/bashrc.d/gpg.bash')
-rw-r--r-- | bash/bashrc.d/gpg.bash | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/bash/bashrc.d/gpg.bash b/bash/bashrc.d/gpg.bash index 83bda3d7..3f01db64 100644 --- a/bash/bashrc.d/gpg.bash +++ b/bash/bashrc.d/gpg.bash @@ -14,23 +14,22 @@ gpg() { # Completion for gpg with long options _gpg() { - local word - word=${COMP_WORDS[COMP_CWORD]} + + # Complete with directories/files if no matches + compopt -o default # Bail if no gpg(1) - if ! hash gpg 2>/dev/null ; then - return 1 - fi + hash gpg 2>/dev/null || return 1 - # Bail if word doesn't start with two dashes - if [[ $word != --* ]] ; then - return 1 - fi + # Bail if not completing an option + [[ ${COMP_WORDS[COMP_CWORD]} == --* ]] || return 1 - # Generate completion reply - COMPREPLY=( $(compgen -W \ - "$(gpg --dump-options 2>/dev/null)" \ - -- "$word") ) + # 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 +complete -F _gpg gpg |