From 05b2ed1e67ce5afdd746bb49ea0383436972d93c Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 10 Jan 2023 09:11:42 +0100 Subject: [PATCH] [bw] Add bwu wrapper around bw login/unlock to automatically export session key. --- .bashrc.dotfiles | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.bashrc.dotfiles b/.bashrc.dotfiles index 9aef5d6..b10958f 100644 --- a/.bashrc.dotfiles +++ b/.bashrc.dotfiles @@ -78,3 +78,22 @@ if command -v nvim &> /dev/null; then else export EDITOR=vim fi + +# Wrapper around bw login/unlock that automatically export the session key +if command -v bw &> /dev/null ; then + function bwu () { + if [ -z "${BW_SESSION}" ]; then + export BW_SESSION + case "$(bw status)" in + *"\"unauthenticated\""*) + echo "(bwu) bw login:" + BW_SESSION=$(bw login --raw) + ;; + *"\"locked\""*) + echo "(bwu) bw unlock:" + BW_SESSION=$(bw unlock --raw) + ;; + esac + fi + } +fi