diff --git a/roles/user/secrets/bw/tasks/main.yml b/roles/user/secrets/bw/tasks/main.yml index 58d543f..9f9a0d0 100644 --- a/roles/user/secrets/bw/tasks/main.yml +++ b/roles/user/secrets/bw/tasks/main.yml @@ -11,29 +11,13 @@ path: ~/.local/bin/bw mode: u+x -- name: Run the CLI to create initial file - ansible.builtin.command: - # See https://github.com/bitwarden/clients/issues/6144 - cmd: "~/.local/bin/bw --version" - creates: ~/.config/Bitwarden CLI/data.json - -- name: Create data stores for specific deployments - ansible.builtin.copy: - src: ~/.config/Bitwarden CLI/data.json - dest: ~/.config/Bitwarden CLI/{{ item }}.json +- name: Create directories for different Bitwarden accounts + ansible.builtin.file: + path: "~/.config/Bitwarden CLI/{{ item }}" + state: directory mode: 0600 - force: false - remote_src: true + owner: "{{ target_user }}" + group: "{{ target_user }}" loop: - vault.bitwarden.com - vault.mfocko.xyz - -- name: Symlink to the self-hosted deployment - ansible.builtin.file: - src: ~/.config/Bitwarden CLI/vault.mfocko.xyz.json - path: ~/.config/Bitwarden CLI/data.json - force: true - state: link -# - name: Switch the server on the self-hosted “login” -# ansible.builtin.command: -# cmd: bw config server https://vault.mfocko.xyz diff --git a/roles/user/shell/zsh/files/zshrc b/roles/user/shell/zsh/files/zshrc index 22a0e3c..66fe13f 100644 --- a/roles/user/shell/zsh/files/zshrc +++ b/roles/user/shell/zsh/files/zshrc @@ -64,21 +64,25 @@ export SDKMAN_DIR="/opt/sdkman" eval "$(bw completion --shell zsh); compdef _bw bw;" function bwu() { - local VAULT=$(readlink ~/.config/Bitwarden\ CLI/data.json | cut -d'/' -f6 | cut -d'.' -f-3) + local VAULT=$(basename $BITWARDENCLI_APPDATA_DIR) local PASS=$(yad --text "Master password for Bitwarden Vault @ $VAULT:" --center --button "yad-ok" --entry --hide-text) export BW_SESSION=$(bw unlock --raw "$PASS") } -# alias bwu='export BW_SESSION="$(bw unlock --raw)"' alias bwl='export BW_SESSION=' -alias bwrh='ln -sf $HOME/.config/Bitwarden\ CLI/{vault.bitwarden.com,data}.json' -alias bwvps='ln -sf $HOME/.config/Bitwarden\ CLI/{vault.mfocko.xyz,data}.json' +function bwrh() { + export BITWARDENCLI_APPDATA_DIR="$HOME/.config/Bitwarden CLI/vault.bitwarden.com" +} +function bwvps() { + export BITWARDENCLI_APPDATA_DIR="$HOME/.config/Bitwarden CLI/vault.mfocko.xyz" +} +bwvps function gen_pass() { LENGTH=12 if [[ -n $1 ]]; then - LENGTH=$1 + LENGTH=$1 fi bw generate -uln --length $LENGTH @@ -87,7 +91,7 @@ function gen_pass() { function gen_passphrase() { LENGTH=2 if [[ -n $1 ]]; then - LENGTH=$1 + LENGTH=$1 fi bw generate -p --words $LENGTH