From 0f8ee4fa839e4d4dd6573599d340a874f0686a46 Mon Sep 17 00:00:00 2001 From: Florian Beisel Date: Fri, 7 Jun 2024 00:56:22 +0200 Subject: [PATCH] Update .zshrc Add update_unlock_bitwarden.sh --- dot_zshrc.tmpl | 2 ++ run_before_update_unlock_bitwarden.sh.tmpl | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 run_before_update_unlock_bitwarden.sh.tmpl diff --git a/dot_zshrc.tmpl b/dot_zshrc.tmpl index 3dfe9ad..c78246a 100644 --- a/dot_zshrc.tmpl +++ b/dot_zshrc.tmpl @@ -61,6 +61,8 @@ source $ZSH/oh-my-zsh.sh # alias ohmyzsh="mate ~/.oh-my-zsh" alias bw='NODE_OPTIONS="--no-deprecation" bw' +alias bwu="export BW_SESSION=$(bw unlock --raw)" + export NODE_OPTIONS="--no-deprecation" # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. diff --git a/run_before_update_unlock_bitwarden.sh.tmpl b/run_before_update_unlock_bitwarden.sh.tmpl new file mode 100644 index 0000000..271243e --- /dev/null +++ b/run_before_update_unlock_bitwarden.sh.tmpl @@ -0,0 +1,27 @@ +#!/bin/bash + +# Function to check if Bitwarden CLI is installed +is_bw_installed() { + command -v bw >/dev/null 2>&1 +} + +# Function to unlock the Bitwarden vault +unlock_vault() { + echo "Unlocking Bitwarden vault..." + BW_SESSION=$(bw unlock --raw) + export BW_SESSION + if [ -n "$BW_SESSION" ]; then + echo "Vault unlocked successfully." + bw sync + else + echo "Failed to unlock vault." + fi +} + +# Check if Bitwarden CLI is installed +if is_bw_installed; then + unlock_vault +else + echo "Bitwarden CLI is not installed, doing nothing." +fi +