diff --git a/src/_utils/_git_secret_tools.sh b/src/_utils/_git_secret_tools.sh index 87209f7a..530215c8 100644 --- a/src/_utils/_git_secret_tools.sh +++ b/src/_utils/_git_secret_tools.sh @@ -620,10 +620,10 @@ function _get_users_in_gpg_keyring { args+=( "--homedir" "$homedir" ) fi - # pluck out 'uid' lines, fetch 10th field, extract part in <> if it exists (else leave alone). # we use --fixed-list-mode so older versions of gpg emit 'uid:' lines. - # sed at the end is to extract email from <>. (If there's no <>, then the line is just an email address anyway.) - result=$($SECRETS_GPG_COMMAND "${args[@]}" --no-permission-warning --list-public-keys --with-colon --fixed-list-mode | grep ^uid: | cut -d: -f10 | sed 's/.*<\(.*\)>.*/\1/') + # here gawk splits on colon as --with-colon, exact matches field 1 as 'uid', and selects field 10 "User-ID" + # the gensub regex extracts email from <> within field 10. (If there's no <>, then field is just an email address anyway and the regex just passes it through.) + result=$($SECRETS_GPG_COMMAND "${args[@]}" --no-permission-warning --list-public-keys --with-colon --fixed-list-mode | gawk -F: '$1~/uid/{print gensub(/.*<(.*)>.*/, "\\1", "g", $10); }') echo "$result" }