Move custom git credential helper from .bashrc to .gitconfig.

This commit is contained in:
2024-08-14 10:30:33 +12:00
parent 7be5292542
commit e4f12c16b5
2 changed files with 5 additions and 49 deletions

48
.bashrc
View File

@ -80,54 +80,6 @@ function bwai () {
bw encode | bw create item && bw sync
}
# custom git credential cache implementation for bitwarden
# https://github.com/bitwarden/cli/blob/master/examples/git-credential-bw.sh
function bw_gitea () {
declare -A params
if [[ "$1" == "get" ]]; then
read -r line
while [ -n "$line" ]; do
key=${line%%=*}
value=${line#*=}
params[$key]=$value
read -r line
done
if [[ "${params['protocol']}" != "https" ]]; then
exit
fi
if [[ -z "${params["host"]}" ]]; then
exit
fi
if ! bw list items --search "asdf" > /dev/null 2>&1; then
echo "Please login to Bitwarden to use git credential helper" > /dev/stderr
exit
fi
id=$(bw list items --search "${params["host"]}"|jq ".[] | select(.name == \"${params["host"]}\").id" -r)
if [[ -z "$id" ]]; then
echo "Couldn't find item id in Bitwarden DB." > /dev/stderr
echo "${params}"
exit
fi
user=$(bw get username "${id}")
pass=$(bw get password "${id}")
if [[ -z "$user" ]] || [[ -z "$pass" ]]; then
echo "Couldn't find host in Bitwarden DB." > /dev/stderr
exit
fi
echo username="$user"
echo password="$pass"
fi
}
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).

View File

@ -1,7 +1,7 @@
[user]
email = mail@jamesblair.net
name = James Blair
signingkey = ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC2t1GmNmhoV2WvrA5dKS9nhLlBExD949coqQnYnqvgQ7l+ODRXxifg8wcnp7PXTcs6CW3tlwA6W5LWMK5gtjNXfZH9jpMPD2m1p7koysoYmC2eMWREF+IN4dS1MsaL9VU1WrqolP3qbvI2WWmECrzA0xakDhAZXuIzl3HRng1YeQV8gi8YoG9Jm0ZXd+RMqxBGyUw1+O4o1NfFwQ9dIUNFRyUScl/yzQv0AfXqOi2IrdA5IpdtlpAZsD1cnB3kUFlluxaq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hrwnXqNuxpMyWsfy5UrTfe67GP2+jzriFxteTMbvZjmgbF2UDMYs5U59NaYPdAYxjwdzH5nHoIWw== james@james-desktop
[pull]
rebase = true
@ -18,6 +18,10 @@
[credential]
helper = cache --timeout=21600
[credential "https://gitea.jamma.life"]
username = "!f() { test \"$1\" = get && echo \"password=$(NODE_OPTIONS=\"--no-deprecation\" bw get username gitea)\"; }; f"
helper = "!f() { test \"$1\" = get && echo \"password=$(NODE_OPTIONS=\"--no-deprecation\" bw get item gitea | jq '.fields[0].value' -r)\"; }; f"
[commit]
gpgsign = true