replace grep+cut+sed pipe with awk regex (#462)

pull/469/head
Simon Massey 5 years ago committed by GitHub
parent aec3ac1ae2
commit 57903b9e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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"
}

Loading…
Cancel
Save