identity.sh: changed add_identity to import_identity
This commit is contained in:
parent
4036ad73fc
commit
46a0dbba0a
|
@ -2,45 +2,61 @@
|
||||||
|
|
||||||
identities="$HOME/.local/share/git/identities";
|
identities="$HOME/.local/share/git/identities";
|
||||||
|
|
||||||
function add_identity() {
|
function import_identity() {
|
||||||
uid_regex="([^\(]*)\s*(\((.*)\))?\s*<(.*)>";
|
local gpg_key_id="$1"
|
||||||
|
filepath="$identities/$2";
|
||||||
|
|
||||||
uid=$(gpg --with-colons -K $1 | awk -F: '$1=="uid" {print $10; exit}');
|
local uid_regex="([^\(]* )\s*(\((.*)\))?\s*<(.*)>";
|
||||||
|
|
||||||
|
local uid=$(gpg --with-colons -K $gpg_key_id | awk -F: '$1=="uid" {print $10; exit}');
|
||||||
|
|
||||||
if [ -z "$uid" ]; then
|
if [ -z "$uid" ]; then
|
||||||
echo "ERROR: found no gpg key matching this";
|
echo "ERROR: found no gpg key matching this";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
name=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\1/");
|
local name=$(printf "$uid" | sed -Ee "s/$uid_regex/\1/" | xargs);
|
||||||
email=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\4/");
|
local email=$(printf "$uid" | sed -Ee "s/$uid_regex/\4/");
|
||||||
|
|
||||||
echo "using this identity:";
|
git config -f "$filepath" user.name "$name"
|
||||||
echo " name = $name";
|
git config -f "$filepath" user.email "$email"
|
||||||
echo " email = $email";
|
|
||||||
|
|
||||||
git config --local user.name "$name"
|
local keyid=$(gpg -K --with-colon $1 | awk -F: '$12~/.*s.*/ {print $5; exit}');
|
||||||
git config --local user.email "$email"
|
|
||||||
|
|
||||||
keyid=$(gpg -K --with-colon $1 | awk -F: '$12~/.*s.*/ {print $5; exit}');
|
|
||||||
# TODO: if multiple found, bring up a dialog to select the right key
|
# TODO: if multiple found, bring up a dialog to select the right key
|
||||||
|
|
||||||
if [ -z "$keyid" ]; then
|
if [ -z "$keyid" ]; then
|
||||||
echo "WARNING: found no subkey with signing capabilities. No signing key will be set";
|
echo "WARNING: found no subkey with signing capabilities. No signing key will be set";
|
||||||
git config --local --unset user.signingKey;
|
git config -f "$filepath" --unset user.signingKey;
|
||||||
else
|
else
|
||||||
echo " key = $keyid";
|
git config -f "$filepath" user.signingKey "$keyid";
|
||||||
git config --local user.signingKey "$keyid";
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
add)
|
import)
|
||||||
add_identity $2
|
if [ -z "$2" ]; then
|
||||||
|
echo "USAGE:";
|
||||||
|
echo " git identity import <gpg_key_id> [identity_file_name]"
|
||||||
|
echo;
|
||||||
|
echo "Imports an identity from a gpg key. If no filename is provided, it will by default to the identifier you provided for your gpg key"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$3" ]; then
|
||||||
|
import_identity "$2" "$2";
|
||||||
|
else
|
||||||
|
import_identity "$2" "$3";
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "imported into $filepath:"
|
||||||
|
cat "$filepath";
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "USAGE:";
|
echo "USAGE:";
|
||||||
echo " git identity <command>";
|
echo " git identity <command>";
|
||||||
|
echo;
|
||||||
|
echo "COMMANDS:"
|
||||||
|
echo " import: import an identity from a gpg key"
|
||||||
exit 1;
|
exit 1;
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue