commit 1b04ed1452c6c5b1de21fa7cb84c56c22df75b8a
parent 25220e62ea50afd4df4240b20055c54b4773e5f8
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Wed, 18 Nov 2020 11:50:45 +0100
Set up a system for bitwarden session management
Former-commit-id: 063df262d7a0c36e0cbdf98b50270a6cd62907aa
Diffstat:
5 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/scripts/mailsync b/scripts/mailsync
@@ -1,10 +1,15 @@
#!/bin/sh
-BW_SESSION="${BW_SESSION:-$(bw unlock --raw)}"
-[ $? -eq 0 ] || { printf "Could not unlock vault.\n" && exit 1; }
-export BW_SESSION
+if [ -z "$BW_SESSION" ]; then
+ if [ -n "$BW_SESHFILE" ] && [ -f "$BW_SESHFILE" ]; then
+ BW_SESSION="$(cat "$BW_SESHFILE")"
+ else
+ BW_SESSION="$(bw unlock --raw)"
+ [ $? -eq 0 ] || { printf "Could not unlock vault.\n" && exit 1; }
+ fi
+ export BW_SESSION
+fi
mbsync -c /Users/alex/.config/mbsync/mbsyncrc -Va
notmuch new
-
notification_str=""
for i in ~/.local/share/mail/*/[Ii][Nn][Bb][Oo][Xx]/new; do
mailbox_name="$(printf "%s" "$i" | sed 's:^.*mail/::; s:/[Ii][Nn][Bb][Oo][Xx]/new.*$::')"
diff --git a/shell/aliases b/shell/aliases
@@ -26,6 +26,6 @@ alias mpva="mpv --no-audio-display --no-video --volume=50"
alias irrsi="irssi --home=~/.config/irssi"
alias scim="sc-im"
alias mbsync='mbsync -c $HOME/.config/mbsync/mbsyncrc'
-alias mutt='BW_SESSION="$(bw unlock --raw)" neomutt'
+alias mutt='{ [ -f "$BW_SESHFILE" ] && BW_SESSION="$(cat $BW_SESHFILE)" neomutt; } || BW_SESSION="$(bw unlock --raw)" neomutt;'
[ -n "$VIM_TERMINAL" ] && alias vim=vimsend
{ [ -f ~/.config/dark-theme ] && alias bat="bat --theme=1337 --color=always"; } || alias bat="bat --theme=GitHub --color=always"
diff --git a/shell/env b/shell/env
@@ -1,6 +1,7 @@
#!/bin/sh
# vim: foldmethod=marker foldlevel=0
export DOTFILES="$HOME/.dotfiles"
+[ -f "$DOTFILES/shell/secret_env" ] && . "$DOTFILES/shell/secret_env"
if [ -n "$VIM_TERMINAL" ]; then EDITOR="vimsend"
else EDITOR="$(command -v vim)"; fi
@@ -11,6 +12,8 @@ export MUSIC_DIR="/Volumes/HDD/Music/iTunes/iTunes Media/Music"
if command -v bat 1>/dev/null 2>&1 && [ -z "$VIMRUNTIME" ]; then export PAGER="bat"
else export PAGER="less -Ri"; fi
+[ -n "$BW_SESHFILE" ] && [ -f "$BW_SESHFILE" ] && export BW_SESSION="$(cat $BW_SESHFILE)"
+
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
diff --git a/shell/functions b/shell/functions
@@ -143,3 +143,28 @@ if [ -f ~/.fzf.zsh ] || [ -f ~/.fzf.bash ]; then
}
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"
+ 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
+ }
+fi
diff --git a/shell/rc b/shell/rc
@@ -22,4 +22,3 @@ source_if_exists "$DOTFILES"/shell/z/z.sh
# Enable custom aliases and functions
source_if_exists "$DOTFILES/shell/aliases"
source_if_exists "$DOTFILES/shell/functions"
-source_if_exists "$DOTFILES/shell/secret_env"