identity: scaffolding subcommands

This commit is contained in:
kalmenn 2023-12-22 01:54:52 +01:00
parent e9d16de77a
commit 4036ad73fc
Signed by: kalmenn
GPG key ID: F500055C44BC3834

View file

@ -1,43 +1,46 @@
#!/bin/sh #!/bin/sh
if [ -z "$1" ]; then identities="$HOME/.local/share/git/identities";
echo "USAGE:";
echo " git identity <gpg key id>";
echo;
echo "current identity:"; function add_identity() {
echo " name = $(git config user.name)"; uid_regex="([^\(]*)\s*(\((.*)\))?\s*<(.*)>";
echo " email = $(git config user.email)";
echo " key = $(git config user.signingKey)";
exit 1;
fi
uid_regex="([^\(]*)\s*(\((.*)\))?\s*<(.*)>"; uid=$(gpg --with-colons -K $1 | awk -F: '$1=="uid" {print $10; exit}');
uid=$(gpg --with-colons -K $1 | awk -F: '$1=="uid" {print $10; exit}'); if [ -z "$uid" ]; then
echo "ERROR: found no gpg key matching this";
exit 1;
fi
if [ -z "$uid" ]; then name=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\1/");
echo "ERROR: found no gpg key matching this"; email=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\4/");
exit 1;
fi
name=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\1/"); echo "using this identity:";
email=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\4/"); echo " name = $name";
echo " email = $email";
echo "using this identity:"; git config --local user.name "$name"
echo " name = $name"; git config --local user.email "$email"
echo " email = $email";
git config --local user.name "$name" keyid=$(gpg -K --with-colon $1 | awk -F: '$12~/.*s.*/ {print $5; exit}');
git config --local user.email "$email" # TODO: if multiple found, bring up a dialog to select the right key
keyid=$(gpg -K --with-colon $1 | awk -F: '$12~/.*s.*/ {print $5; exit}'); if [ -z "$keyid" ]; then
# TODO: if multiple found, bring up a dialog to select the right key echo "WARNING: found no subkey with signing capabilities. No signing key will be set";
git config --local --unset user.signingKey;
else
echo " key = $keyid";
git config --local user.signingKey "$keyid";
fi
}
if [ -z "$keyid" ]; then case $1 in
echo "WARNING: found no subkey with signing capabilities. No signing key will be set"; add)
git config --local --unset user.signingKey; add_identity $2
else ;;
echo " key = $keyid"; *)
git config --local user.signingKey "$keyid"; echo "USAGE:";
fi echo " git identity <command>";
exit 1;
;;
esac