Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
bash: Add gpg to progcomp
Browse files Browse the repository at this point in the history
  • Loading branch information
h3xx committed Sep 23, 2021
1 parent 9f142cd commit 628f3d3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bash/.bashrc-progcomp
Expand Up @@ -269,6 +269,44 @@ test -n "$(
__git_complete tig __git_complete_revlist
}

# bash completion for gpg
# Source (modified): https://salsa.debian.org/debian/bash-completion/-/blob/master/completions/gpg

_gpg() {
local \
CUR=${COMP_WORDS[$COMP_CWORD]} \
PREV=${COMP_WORDS[$COMP_CWORD-1]} \

case "$PREV" in
--sign | --clearsign | --decrypt-files | --load-extension | -!(-*)s)
# Complete default (files and dirs)
return
;;
--export | --sign-key | --lsign-key | --nrsign-key | --nrlsign-key | --edit-key)
# return list of public keys
COMPREPLY=($(compgen -W "$($1 --list-keys 2>/dev/null | sed -ne \
's@^pub.*/\([^ ]*\).*$@\1@p' -ne \
's@^.*\(<\([^>]*\)>\).*$@\2@p')" -- "$CUR"))
return
;;
--recipient | -!(-*)r)
COMPREPLY=($(compgen -W "$($1 --list-keys 2>/dev/null | sed -ne \
's@^.*<\([^>]*\)>.*$@\1@p')" -- "$CUR"))
if [[ -e ~/.gnupg/gpg.conf ]]; then
COMPREPLY+=($(compgen -W "$(sed -ne \
's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' \
~/.gnupg/gpg.conf)" -- "$CUR"))
fi
return
;;
esac

if [[ $CUR = -* ]]; then
COMPREPLY=($(compgen -W '$($1 --dump-options)' -- "$CUR"))
fi
} &&
complete -F _gpg -o default gpg

# XXX : debugging function
#_listcomp() {
# local varname
Expand Down

0 comments on commit 628f3d3

Please sign in to comment.