diff --git a/config b/config index 001a3ad..d9c10d3 100644 --- a/config +++ b/config @@ -10,6 +10,7 @@ [core] editor = nvim + quotepath = off [init] defaultBranch = main @@ -31,25 +32,28 @@ s = "status" # custom git log (inline) - # sed part courtesy of: https://stackoverflow.com/questions/17371955/verifying-signed-git-commits/32038784#comment124980964_32038784 lgi = "!f() { \ git 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)' | \ + --format='%C(bold dim green)%h%C(auto) - %C(yellow)%cr %C(bold)→%C(reset) %s%C(reset bold yellow)%d %an %G? %GS %C(reset)' | \ 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##'; \ + -e 's#\\(.*\\) N .*#\\x1b[0;2;3;37m- \\1#' \ + -e 's#\\(.*\\) E .*#\\x1b[1;33mMissing Key: \\x1b[0;2;3;37m\\1#' \ + \ + -e 's#.* \\([^N]\\)#\\1#' \ + \ + -e 's#G#\\x1b[0;1;32mGood:#' \ + -e 's#R#\\x1b[1;32mGood (revoked since):#' \ + -e 's#X#\\x1b[1;32mGood (expired since):#' \ + -e 's#U#\\x1b[1;33mUnknown Trust:#' \ + -e 's#Y#\\x1b[1;33mExpired Key:#' \ + -e 's#B#\\x1b[1;31mBAD:#' \ + -e 's#\\(.*\\)#\\x1b[0;2;3;37m\\1#'; \ }; f" # custom git log (always opens in pager) lg = "!f() { \ git lgi $@ | \ - less -cr; \ + less --clear-screen --RAW-CONTROL-CHARS --chop-long-lines; \ }; f" # Inspired by, then evolved from: diff --git a/scripts/identity.sh b/scripts/identity.sh index a5f9acc..652f651 100755 --- a/scripts/identity.sh +++ b/scripts/identity.sh @@ -4,6 +4,12 @@ no_home_identities=".local/share/git/identities" identities="$HOME/$no_home_identities"; mkdir -p "$identities"; +if [ ! -z "$(git config core.editor)" ]; then + EDITOR="$(git config core.editor)"; +elif [ ! -z "$GIT_EDITOR" ]; then + EDITOR="$GIT_EDITOR"; +fi + function yes_or_no { # courtesy of: https://stackoverflow.com/a/29436423 while true; do read -p "$* [y/n]: " yn; @@ -28,8 +34,11 @@ function display_parts() { local email="$3"; local sigkey="$4"; - printf "[$identity] $name <$email>"; - if [ ! -z $sigkey ]; then + if [ ! -z "$identity" ]; then + printf "[$identity] "; + fi + printf "$name <$email>"; + if [ ! -z "$sigkey" ]; then printf " (signing key: $sigkey)"; fi printf "\n"; @@ -128,7 +137,7 @@ case $1 in echo; echo "Copies the config from an identity to the local git config."; echo "Using set instead of link essentially means that future changes made to the identity will not be synced with the local git config."; - echo "If you wish for that be the case, you can manually include the identity in your local git config like so:"; + echo "If you wish for that be the case, consider using the include subcommand instead."; echo; echo "[include]"; echo " path = ~/$no_home_identities/" @@ -144,9 +153,47 @@ case $1 in [ ! -z "$email" ] && git config user.email "$email"; [ ! -z "$sigkey" ] && git config user.signingKey "$sigkey"; ;; + include) + if [ -z "$2" ]; then + echo "USAGE:"; + echo; + echo " git identity include "; + echo; + echo "Takes the path of the file in which the identity is defined and includes it in your local git config."; + echo "This means that any changes made to the identity will be kept in sync in this local confif, risking a loss of consistency for the identity that's shown in your commits." + exit 1; + fi + + get_identity "$2"; + + echo "Using this identity:"; + display_identity "$identity"; + echo; + + git_config="$GIT_DIR/config"; + + echo "Writing to $git_config"; + echo; + + echo -e "[include]\n path = ~/$no_home_identities/$identity" >> "$git_config"; + + res=0; + + set -m; + + #while [ "$res" -eq 0 ]; do # TODOOOOOOOOOOOO + echo "Your new identity is:"; + display_parts "" "$(git config user.name)" "$(git config user.email)" "$(git config user.signingKey)"; + yes_or_no "Is this good (otherwise, review the config)"; + res=$?; + if [ "$res" -eq 1 ]; then + $EDITOR "$git_config"; + fi + #done + ;; show) if [ -z "$2" ]; then - display_parts "current" "$(git config user.name)" "$(git config user.email)" "$(git config user.signingKey)"; + display_parts "" "$(git config user.name)" "$(git config user.email)" "$(git config user.signingKey)"; else get_identity "$2"; display_identity "$identity"; @@ -163,7 +210,8 @@ case $1 in echo " import: Imports an identity from a gpg key"; echo " remove: Removes a saved identity"; echo " set: Sets the identity of the current git repo"; - echo " show: Show a saved identity or the identity of the current repo"; + echo " include: Includes the identity file in your local git config" + echo " show: Show a saved identity or the identity that's currently effective"; echo " list: List all saved identities"; exit 1; ;;