identity: list saved identities

This commit is contained in:
kalmenn 2023-12-22 12:08:01 +01:00
parent be18a14d0f
commit b7c54c6252
Signed by: kalmenn
GPG key ID: F500055C44BC3834

View file

@ -2,6 +2,12 @@
identities="$HOME/.local/share/git/identities"; 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() { function import_identity() {
local gpg_key_id="$1" local gpg_key_id="$1"
filepath="$identities/$2"; filepath="$identities/$2";
@ -32,6 +38,19 @@ function import_identity() {
fi 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 case $1 in
import) import)
if [ -z "$2" ]; then if [ -z "$2" ]; then
@ -51,10 +70,15 @@ case $1 in
echo "imported into $filepath:" echo "imported into $filepath:"
cat "$filepath"; cat "$filepath";
;; ;;
list)
list_identities;
;;
*) *)
echo "USAGE:"; echo "USAGE:";
echo " git identity <command>"; echo " git identity <command>";
echo; echo;
echo "Saved identities can be found here: $identities";
echo;
echo "COMMANDS:" echo "COMMANDS:"
echo " import: import an identity from a gpg key" echo " import: import an identity from a gpg key"
echo " remove: removed a saved identity"; echo " remove: removed a saved identity";