aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-10-28 23:34:49 -0400
committerGitHub <noreply@github.com>2021-10-28 23:34:49 -0400
commit6f5d1309874c5dfbc9b151d0b7a5a840f4a3de1a (patch)
tree1fdbc7e6eddad8a513d96458515efc2a17b20e1f
parent7e5b1b1452c17ba5c5c253a6eec3ad5d076b5fa6 (diff)
parent1adf7ed3ba3ea711e00bc21c626691c6ce3d4a1b (diff)
downloadrbw-6f5d1309874c5dfbc9b151d0b7a5a840f4a3de1a.tar.gz
rbw-6f5d1309874c5dfbc9b151d0b7a5a840f4a3de1a.zip
Merge pull request #41 from xPMo/master
Add git-credential-helper
-rwxr-xr-xbin/git-credential-rbw34
1 files changed, 34 insertions, 0 deletions
diff --git a/bin/git-credential-rbw b/bin/git-credential-rbw
new file mode 100755
index 0000000..102aade
--- /dev/null
+++ b/bin/git-credential-rbw
@@ -0,0 +1,34 @@
+#!/bin/sh
+set -f
+
+[ "$1" = get ] || exit
+
+while read -r line; do
+ case $line in
+ protocol=*)
+ protocol=${line#*=} ;;
+ host=*)
+ host=${line#*=} ;;
+ username=*)
+ user=${line#*=} ;;
+ esac
+done
+
+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
+
+printf '%s\n' "$output" | sed -n '
+ 1{ s/^/password=/p }
+ s/^Username: /username=/p
+ s/^URI: /host=/p
+ '