From 243ce1b91db00e6773ef8ee8cd7e1f464400b38d Mon Sep 17 00:00:00 2001 From: kalmenn Date: Thu, 21 Dec 2023 22:49:17 +0100 Subject: [PATCH] initial commit --- config | 34 ++++++++++++++++++++++++++++++++++ scripts/identity.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 config create mode 100755 scripts/identity.sh diff --git a/config b/config new file mode 100644 index 0000000..a1a68ea --- /dev/null +++ b/config @@ -0,0 +1,34 @@ +[core] + editor = nvim +[init] + defaultBranch = main +[commit] + gpgsign = true +[filter "lfs"] + required = true + clean = git-lfs clean -- %f + smudge = git-lfs smudge -- %f + process = git-lfs filter-process +[user] + useConfigOnly = true + +[alias] + lg-inline = "log --graph --branches --all --date=human --color --format='%C(bold dim green)%h%C(auto) - %C(yellow)%<(12)%cr %C(bold)→%C(reset) %s%C(dim white) - %an %C(bold green)%G?%GS%C(reset cyan)%d%C(reset)'" + # sed part courtesy of: https://stackoverflow.com/a/32038784 + lg = "!f() { \ + git lg-inline $@ |\ + sed \ + -e 's#G#Good Signature: #' \ + -e 's#B#\\x1b[31mBAD#' \ + -e 's#U#\\x1b[33mUnknown Trust: #' \ + -e 's#X#Good | Expired#' \ + -e 's#Y#\\x1b[33mExpired Key#' \ + -e 's#R#\\x1b[31mRevoked#' \ + -e 's#E#\\x1b[33mMissing Key#' \ + -e 's#N##' | \ + less -cr; \ + }; f" + ck = "checkout" + s = "status" + # https://www.micah.soy/posts/setting-up-git-identities/ + identity = "!~/.config/git/scripts/identity.sh" diff --git a/scripts/identity.sh b/scripts/identity.sh new file mode 100755 index 0000000..9781d15 --- /dev/null +++ b/scripts/identity.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "USAGE:"; + echo " git identity "; + echo; + + echo "current identity:"; + echo " name = $(git config user.name)"; + 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}'); + +if [ -z "$uid" ]; then + echo "ERROR: found no gpg key matching this"; + exit 1; +fi + +name=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\1/"); +email=$(printf "$uid" | sed --regexp-extended -e "s/$uid_regex/\4/"); + +echo "using this identity:"; +echo " name = $name"; +echo " email = $email"; + +git config --local user.name "$name" +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 + +if [ -z "$keyid" ]; then + 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