commit 75f4747fb48921798d3ef84363c4fa42aa61820b
parent f73b292f6f0513820521c85efddd5c7085a95e32
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Thu, 19 Nov 2020 12:59:17 +0100
Changed bitwarden setup so launchd job can lock
Former-commit-id: d66106610a33dee8097adbb4ff3e4377cb643303
Diffstat:
4 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/scripts/bwg b/scripts/bwg
@@ -0,0 +1,4 @@
+#!/bin/sh
+command -v bw 1>/dev/null 2>&1 || { printf "Bitwarden CLI not installed.\n" && exit 1; }
+[ -n "$BW_SESHFILE" ] || { printf "Set BW_SESHFILE in your env.\n" && exit 1; }
+{ [ -f "$BW_SESHFILE" ] && cat "$BW_SESHFILE"; } || printf "No active session.\n"
diff --git a/scripts/bwl b/scripts/bwl
@@ -0,0 +1,5 @@
+#!/bin/sh
+command -v bw 1>/dev/null 2>&1 || { printf "Bitwarden CLI not installed.\n" && exit 1; }
+[ -n "$BW_SESHFILE" ] || { printf "Set BW_SESHFILE in your env.\n" && exit 1; }
+[ -f "$BW_SESHFILE" ] && rm "$BW_SESHFILE"
+bw lock
diff --git a/scripts/bwu b/scripts/bwu
@@ -0,0 +1,13 @@
+#!/bin/sh
+command -v bw 1>/dev/null 2>&1 || { printf "Bitwarden CLI not installed.\n" && exit 1; }
+[ -n "$BW_SESHFILE" ] || { printf "Set BW_SESHFILE in your env.\n" && exit 1; }
+if ! [ -f "$BW_SESHFILE" ]; then
+ touch "$BW_SESHFILE"
+ chmod 600 "$BW_SESHFILE"
+ { bw unlock --raw > "$BW_SESHFILE" \
+ && printf "Vault unlocked.\n"; } \
+ || rm "$BW_SESHFILE";
+else
+ printf "Session already active.\n"
+fi
+
diff --git a/shell/functions b/shell/functions
@@ -146,25 +146,11 @@ fi
# bitwarden functions
if command -v bw 1>/dev/null 2>&1; then
bwl() {
- [ -n "$BW_SESHFILE" ] || { printf "Set BW_SESHFILE in your env.\n" && exit 1; }
- [ -f "$BW_SESHFILE" ] && rm "$BW_SESHFILE"
+ command bwl
unset BW_SESSION
- bw lock
- }
- bwg() {
- [ -n "$BW_SESHFILE" ] || { printf "Set BW_SESHFILE in your env.\n" && exit 1; }
- { [ -f "$BW_SESHFILE" ] && cat "$BW_SESHFILE"; } || printf "No active session.\n"
}
bwu() {
- [ -n "$BW_SESHFILE" ] || { printf "Set BW_SESHFILE in your env.\n" && exit 1; }
- if ! [ -f "$BW_SESHFILE" ]; then
- touch "$BW_SESHFILE"
- chmod 600 "$BW_SESHFILE"
- bw unlock --raw > "$BW_SESHFILE"
- printf "Vault unlocked.\n"
- export BW_SESSION="$(cat $BW_SESHFILE)"
- else
- printf "Session already active.\n"
- fi
+ command bwu
+ [ -f "$BW_SESHFILE" ] && export BW_SESSION="$(cat $BW_SESHFILE)"
}
fi