From b7c54c62522bd143401f3699ca82feb17bddce9d Mon Sep 17 00:00:00 2001 From: kalmenn Date: Fri, 22 Dec 2023 12:08:01 +0100 Subject: [PATCH] identity: list saved identities --- scripts/identity.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/identity.sh b/scripts/identity.sh index f01fccd..65ccc26 100755 --- a/scripts/identity.sh +++ b/scripts/identity.sh @@ -2,6 +2,12 @@ identities="$HOME/.local/share/git/identities"; +function get_identity() { + sigkey=$(git config -f "$1" user.signingKey); + name=$(git config -f "$1" user.name) + email=$(git config -f "$1" user.email); +} + function import_identity() { local gpg_key_id="$1" filepath="$identities/$2"; @@ -32,6 +38,19 @@ function import_identity() { fi } +function list_identities() { + local sigkey name email; + for id_file in $identities/*; do + get_identity "$id_file"; + + printf "$name <$email>"; + if [ ! -z $sigkey ]; then + printf " (signing key: $sigkey)"; + fi + printf "\n"; + done +} + case $1 in import) if [ -z "$2" ]; then @@ -51,10 +70,15 @@ case $1 in echo "imported into $filepath:" cat "$filepath"; ;; + list) + list_identities; + ;; *) echo "USAGE:"; echo " git identity "; echo; + echo "Saved identities can be found here: $identities"; + echo; echo "COMMANDS:" echo " import: import an identity from a gpg key" echo " remove: removed a saved identity";