feat(git): configure age textconv

This commit is contained in:
Peter 2024-02-07 07:52:48 +01:00
parent ddae1cfb1e
commit 7055986bb2
Signed by: prskr
GPG key ID: F56BED6903BC5E37
2 changed files with 34 additions and 34 deletions

View file

@ -59,3 +59,6 @@
clean = git-age clean -- %f
smudge = git-age smudge -- %f
required = true
[diff "age"]
textconv = cat

View file

@ -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
'