aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--bash/bashrc.d/gnupg.bash22
2 files changed, 23 insertions, 0 deletions
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
+