diff --git a/dot_gitconfig.tmpl b/dot_gitconfig.tmpl index d4a28dd..fefbb92 100644 --- a/dot_gitconfig.tmpl +++ b/dot_gitconfig.tmpl @@ -59,3 +59,6 @@ clean = git-age clean -- %f smudge = git-age smudge -- %f required = true + +[diff "age"] + textconv = cat diff --git a/private_dot_local/bin/executable_git-credential-rbw b/private_dot_local/bin/executable_git-credential-rbw index e6f9bbb..5d66d32 100644 --- a/private_dot_local/bin/executable_git-credential-rbw +++ b/private_dot_local/bin/executable_git-credential-rbw @@ -1,5 +1,5 @@ -#!/opt/homebrew/Cellar/bash/5.2.21/bin/bash - +#!/usr/bin/env bash +# # rbw git-credential helper # Based on https://github.com/lastpass/lastpass-cli/blob/master/contrib/examples/git-credential-lastpass @@ -9,39 +9,36 @@ # 1. Put this somewhere in your path. # 2. git config --global credential.helper rbw -declare -A params +set -f -if [ "x$1" == "xget" ]; then - read line - while [ -n "$line" ]; do - key=${line%%=*} - value=${line#*=} - params[$key]=$value - read line - done +[ "$1" = get ] || exit - if [ "x${params['protocol']}" != "xhttps" ]; then - exit - fi +while read -r line; do + case $line in + protocol=*) + protocol=${line#*=} ;; + host=*) + host=${line#*=} ;; + username=*) + user=${line#*=} ;; + esac +done - if [ -z "${params["host"]}" ]; then - exit - fi +output= +#shellcheck disable=2154 +for arg in \ + "${protocol:+$protocol://}$host" \ + "$host" \ + "${host2=${host%.*}}" \ + "${host2#*.}" +do + # exit on first good result + [ -n "$user" ] && output=$(rbw get --full "$arg" "$user") && break + output=$(rbw get --full "$arg") && break +done || exit - rbw ls > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "Please login to rbw to use git credential helper" > /dev/stderr - exit - fi - - user=`rbw get --full ${params["host"]} | grep "Username:" | cut -d' ' -f2-` - pass=`rbw get ${params["host"]}` - - if [ "x$user" == "x" ] || [ "x$pass" == "x" ]; then - echo "Couldn't find host in rbw DB." > /dev/stderr - exit - fi - - echo username=$user - echo password=$pass -fi +printf '%s\n' "$output" | sed -n ' + 1{ s/^/password=/p } + s/^Username: /username=/p + s/^URI: /host=/p + '