2006-01-13 14:41:33 +00:00
|
|
|
#
|
2010-09-18 02:18:26 +00:00
|
|
|
# Completions for the gpg command.
|
2006-01-13 14:41:33 +00:00
|
|
|
#
|
|
|
|
# This program accepts an rather large number of switches. It allows
|
|
|
|
# you to do things like changing what file descriptor errors should be
|
|
|
|
# written to, to make gpg use a different locale than the one
|
|
|
|
# specified in the environment or to specify an alternative home
|
|
|
|
# directory.
|
2006-01-14 01:59:37 +00:00
|
|
|
|
2006-01-13 14:41:33 +00:00
|
|
|
# Switches related to debugging, switches whose use is not
|
|
|
|
# recommended, switches whose behaviour is as of yet undefined,
|
|
|
|
# switches for experimental features, switches to make gpg compliant
|
2006-01-15 11:59:08 +00:00
|
|
|
# to legacy pgp-versions, dos-specific switches, switches meant for
|
|
|
|
# the options file and deprecated or obsolete switches have all been
|
|
|
|
# removed. The remaining list of completions is still quite
|
|
|
|
# impressive.
|
2006-01-13 14:41:33 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Various functions used for dynamic completions
|
|
|
|
#
|
|
|
|
|
2019-09-03 01:13:53 +00:00
|
|
|
|
2006-01-13 14:41:33 +00:00
|
|
|
function __fish_complete_gpg_user_id -d "Complete using gpg user ids"
|
2019-05-05 10:53:09 +00:00
|
|
|
# gpg doesn't seem to like it when you use the whole key name as a
|
2019-09-08 19:01:44 +00:00
|
|
|
# completion, so we skip the <EMAIL> part and use it as a
|
2019-05-05 10:53:09 +00:00
|
|
|
# description.
|
|
|
|
# It also replaces colons with \x3a
|
|
|
|
gpg --list-keys --with-colon | cut -d : -f 10 | sed -ne 's/\\\x3a/:/g' -e 's/\(.*\) <\(.*\)>/\1'\t'\2/p'
|
2006-01-13 14:41:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_complete_gpg_key_id -d 'Complete using gpg key ids'
|
2019-09-08 19:01:44 +00:00
|
|
|
# Use user id as description
|
|
|
|
set -l keyid
|
2019-05-05 10:53:09 +00:00
|
|
|
gpg --list-keys --with-colons | while read garbage
|
|
|
|
switch $garbage
|
2019-09-08 19:01:44 +00:00
|
|
|
# Extract user ids
|
2019-05-05 10:53:09 +00:00
|
|
|
case "uid*"
|
2019-09-08 19:01:44 +00:00
|
|
|
echo $garbage | cut -d ":" -f 10 | sed -e "s/\\\x3a/:/g" | read uid
|
|
|
|
printf "%s\t%s\n" $keyid $uid
|
|
|
|
# Extract key fingerprints (no subkeys)
|
|
|
|
case "pub*"
|
|
|
|
echo $garbage | cut -d ":" -f 5 | read keyid
|
2019-05-05 10:53:09 +00:00
|
|
|
end
|
|
|
|
end
|
2006-01-13 14:41:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_print_gpg_algo -d "Complete using all algorithms of the type specified in argv[1] supported by gpg. argv[1] is a regexp"
|
2019-05-05 10:53:09 +00:00
|
|
|
# Set a known locale, so that the output format of 'gpg --version'
|
|
|
|
# is at least somewhat predictable. The locale will automatically
|
|
|
|
# expire when the function goes out of scope, and the original locale
|
|
|
|
# will take effect again.
|
|
|
|
set -lx LC_ALL C
|
2016-04-08 02:46:51 +00:00
|
|
|
|
2019-05-05 10:53:09 +00:00
|
|
|
# sed script explained:
|
|
|
|
# in the line that matches "$argv:"
|
|
|
|
# define label 'loop'
|
|
|
|
# if the line ends with a ','
|
|
|
|
# add next line to buffer
|
|
|
|
# transliterate '\n' with ' '
|
|
|
|
# goto loop
|
|
|
|
# remove everything until the first ':' of the line
|
|
|
|
# remove all blanks
|
|
|
|
# transliterate ',' with '\n' (OSX apparently doesn't like '\n' on RHS of the s-command)
|
|
|
|
# print result
|
2019-09-03 00:51:02 +00:00
|
|
|
gpg --version | sed -ne "/$argv:/"'{:loop
|
|
|
|
/,$/{N; y!\n! !
|
|
|
|
b loop
|
|
|
|
}
|
|
|
|
s!^[^:]*:!!
|
|
|
|
s![ ]*!!g
|
|
|
|
y!,!\n!
|
|
|
|
p
|
|
|
|
}'
|
2006-01-13 14:41:33 +00:00
|
|
|
end
|
|
|
|
|
2019-10-04 00:40:23 +00:00
|
|
|
__fish_complete_gpg gpg
|