#!/usr/bin/env fish # This script lets you query entries from bitwarden # using rbw and fuzzel. You can copy, auto-type, or show in notification. # Requires wl-copy, wtype, jq, and rbw. # Intended use: bind this to a key in your window manager # unlock vault if needed # Note: launches foot with 'footfloat' app-id # You can use a window rule in your compositor # to display this as a floating window if you wish # This is to accommodate pinentry-curses or tty if not rbw unlocked foot -w 750x500 -a footfloat rbw unlock # if the unlock failed we quit early if not rbw unlocked return 1 end end # check if action was given as arg, prompt otherwise set -l action if test (count $argv) -ne 0 set action $argv[1] else set action (echo copy\ntype\nshow | fuzzel --prompt="Action> " --dmenu) end if test -z "$action" return 1 end # prompt for query set -l query set -l queries username password code # double query only availably for type action if test "$action" = type set --append queries double end set query (string join \n $queries | fuzzel --prompt="Query> " --dmenu) if test -z "$query" return 1 end # prompt for account selection # $selected is the entry's name used for lookup set -l selected (rbw list | fuzzel --prompt="$query: " --dmenu) if test -z "$selected" return 1 end # get answer to the query for the selected account set -l output if test "$query" = code set output (rbw code "$selected") else if test "$query" = double # special case for i in username password set --append output (rbw get "$selected" --raw | jq --join-output ".data.$i") end else set output (rbw get "$selected" --raw | jq --join-output ".data.$query") end # finally process the output according to action switch $action case copy wl-copy $output case type if test (count $output) -eq 1 wtype "$output" else # special case for double action # to type both user and pass wtype "$output[1]" wtype -k Tab wtype "$output[2]" end case show # notification doesn't time out # until closed by user notify-send --wait "$output" case '*' notify-send "Invalid command!" end