diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-02 17:59:29 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-02 17:59:29 +1300 |
commit | 7d6fe8b1886f902f8ffbec2a9985fae9f91121cb (patch) | |
tree | 282fac0bb1809e726a373916c90260832ab23ced /bash/bash_completion.d/gpg.bash | |
parent | Reduce ud() completion to just dirnames (diff) | |
download | dotfiles-7d6fe8b1886f902f8ffbec2a9985fae9f91121cb.tar.gz dotfiles-7d6fe8b1886f902f8ffbec2a9985fae9f91121cb.zip |
Overhaul Bash completion scripts
Some general changes:
* Apply case sensitivity switching in more contexts, using a dynamically
loaded helper function
* Use array counters for appending to COMPREPLY where possible
* Lots more short-circuiting to limit structural depth
These changes are expansive and there will definitely be bugs.
Diffstat (limited to 'bash/bash_completion.d/gpg.bash')
-rw-r--r-- | bash/bash_completion.d/gpg.bash | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/bash/bash_completion.d/gpg.bash b/bash/bash_completion.d/gpg.bash index bfa2d1a9..c6f92676 100644 --- a/bash/bash_completion.d/gpg.bash +++ b/bash/bash_completion.d/gpg.bash @@ -1,7 +1,7 @@ # Completion for gpg(1) with long options _gpg() { - # Bail if no gpg(1) + # Needs gpg(1) hash gpg 2>/dev/null || return # Bail if not completing an option @@ -11,13 +11,16 @@ _gpg() { esac # Generate completion reply from gpg(1) options - local option - while read -r option ; do - case $option in - "$2"*) - COMPREPLY[${#COMPREPLY[@]}]=$option - ;; - esac - done < <(gpg --dump-options 2>/dev/null) + local ci comp + while read -r comp ; do + COMPREPLY[ci++]=$comp + done < <( + gpg --dump-options 2>/dev/null | + while read -r option ; do + case $option in + ("$2"*) printf '%s\n' "$option" ;; + esac + done + ) } complete -F _gpg -o bashdefault -o default gpg |