#!/bin/sh # local is well supported # shellcheck disable=3043 set -eux # shellcheck disable=2034 description="rbw-based password manager" FUZL_PROMPT=pasm FUZL_ICON=󰈲 . libfuzl.sh main() { rbw unlocked 2>/dev/null || rbw unlock || exit 1 local eid eid=$(rbw_select_entry) fuzl_action_add "copy" "󰀄" "copy username/password" rbw_has_totp "$eid" && fuzl_action_add "totp" "󰎃" "copy totp code" fuzl_action_add "url" "󰌹" "copy url" fuzl_action_menu "$eid" || exit 1 } # # helpers # rbw_select_entry() { rbw list --raw | jq -r '.[] | select(.type=="Login") | [.id,.name,.user,(.uris[0]//"-")]|join("%")' | awk -F% '{print $1 "\t" ($2 " →") "\t" ("󰀄 " $3) "\t" ("󰌹 " $4)}' | fuzl_menu $FUZL_MENU_FILTER --with-nth='{2} {3..}' --accept-nth=1 -w 80 } rbw_has_totp() { local eid=${1:?missing eid} # can't use fuzl_try here because we need the exit status rbw get -l "$eid" | grep -q totp } rbw_entry() { local eid=${1:?missing eid} fuzl_try -- rbw get --raw "$eid" | jq -r '.name' } # # actions # pasm_copy() { local eid=${1:?missing eid} fuzl_try -- rbw get -f password "$eid" | wl-copy -n fuzl_try -- rbw get -f username "$eid" | wl-copy -p -n fuzl_notification "$(rbw_entry "$eid")" "copied to clipboard" } pasm_totp() { local eid=${1:?missing eid} fuzl_try -- rbw totp "$eid" | wl-copy -n fuzl_notification "$(rbw_entry "$eid")" "copied totp to clipboard" } pasm_url() { local eid=${1:?missing eid} fuzl_try -- rbw get -f uris "$eid" | head -n1 | wl-copy -n fuzl_notification "$(rbw_entry "$eid")" "copied url to clipboard" } main