2019-09-25 06:31:44 +08:00
|
|
|
# Helper function for contextual autocompletion of GPG key ids
|
|
|
|
|
2022-02-10 00:40:45 +08:00
|
|
|
function __fish_complete_gpg_key_id -d 'Complete using gpg key ids' -a __fish_complete_gpg_command list_arg
|
2019-09-25 06:31:44 +08:00
|
|
|
# Use user id as description
|
|
|
|
set -l keyid
|
2022-02-10 00:40:45 +08:00
|
|
|
set -q list_arg[1]; or set list_arg --list-keys
|
|
|
|
$__fish_complete_gpg_command $list_arg --with-colons | while read -l garbage
|
2019-09-25 06:31:44 +08:00
|
|
|
switch $garbage
|
|
|
|
case "uid*"
|
2020-02-17 21:12:27 +08:00
|
|
|
# Extract user ids (note: gpg escapes colons as '\x3a')
|
2020-01-22 00:11:36 +08:00
|
|
|
set -l __uid (string split ":" -- $garbage)
|
2020-05-28 07:24:04 +08:00
|
|
|
set -l uid (string replace -a '\x3a' ':' -- $__uid[10])
|
2019-09-25 06:31:44 +08:00
|
|
|
printf "%s\t%s\n" $keyid $uid
|
2022-06-17 00:43:28 +08:00
|
|
|
# NOTE key is preceded by "sec" instead of "pub" when listing secret keys
|
2022-02-10 00:40:45 +08:00
|
|
|
case "pub*" "sec*"
|
2020-02-17 21:12:27 +08:00
|
|
|
# Extract key fingerprints (no subkeys)
|
2020-01-22 00:11:36 +08:00
|
|
|
set -l __pub (string split ":" -- $garbage)
|
|
|
|
set keyid $__pub[5]
|
2019-09-25 06:31:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|