rbuchberger / rbw-menu

Teeny Tiny GUI menu for rbw (Unofficial Bitwarden CLI)
GNU General Public License v3.0
13 stars 1 forks source link

`rbw-menu` not copying password to clipboard using `wl-copy` #2

Closed pfr-dev closed 8 months ago

pfr-dev commented 8 months ago

I am using rbw with rbw-menu to access my Bitwarden database, using pinentry-bemenu as my pinentry and bemenu as the interface.

Here is how I have it set up:

rbw-menu:

#!/bin/ash
set -euo pipefail
IFS=$'\n\t'
# Creator: Robert Buchberger <robert@buchberger.cc>
#                            @robert@spacey.space
#
# Select an item from bitwarden with wofi, return value for passed query
# Dependencies: rbw installed and configured
#
# Usage: rbw-menu [query]
#   query: "code" or anything on the login object; username, password, totp, etc
#     - code will return a TOTP code
#     - anything else will return the value of the query
#   default: username

rbw unlocked &> /dev/null || rbw unlock

query=${1:-password}

chosen_item=$(
    # If RBW_MENU_COMMAND is set, use it to filter the list.
    if declare -p RBW_MENU_COMMAND >&/dev/null; then
        eval "rbw list | $RBW_MENU_COMMAND"  # I have this set to benemu in ~/.profile but this doesn't seem to work.
    else  #use wofi 
        #rbw list | wofi --dmenu --matching fuzzy --insensitive --prompt "$query"
        #
        # Therfore, set it here to use bemenu:
        rbw list | bemenu "$query"
    fi
)

# Exit if user didn't select anything
declare -p chosen_item >&/dev/null || exit 1

case "$query" in
code)
    rbw code "$chosen_item"
    ;;
*)
    # Select chosen item from vault, return login.query
    rbw get "$chosen_item" --raw | jq --join-output ".data.$query"
    ;;
esac

When I execute rbw-menu password | wl-copy from the command line or from my wm's keybinds the password is not copied. However, when I execute rbw get <password> | wl-copy from the command line it works. This leads me to believe that rbw and wl-copy do work, there must be something wront with rbw-menu.

As you might have noiticed from the shebang, I'm using ash on Alpine Linux (in-case there are any bash specific syntax in this script).

Thanks

edit: spelling

rbuchberger commented 8 months ago

Hello! I have no experience with alpine or ash, though I suppose I could spin up a test environment somewhere. Shellcheck does show a lot of issues if I switch the shell to sh or ash, so I believe it does use several bash specific features.

I suppose I should either document that it requires bash, or rewrite it to be POSIX compliant.

rbuchberger commented 8 months ago

Could you try the version in the linked PR? Raw file here for convenience:

https://raw.githubusercontent.com/rbuchberger/rbw-menu/180de52c073dfd4494639f907db5b5583ad81538/bin/rbw-menu

pfr-dev commented 8 months ago

Could you try the version in the linked PR? Raw file here for convenience:

https://raw.githubusercontent.com/rbuchberger/rbw-menu/180de52c073dfd4494639f907db5b5583ad81538/bin/rbw-menu

That works. Thanks :)

Do you plan on merging this PR?

rbuchberger commented 8 months ago

Sure do! Just wanted to make sure it works before doing so. Thanks for testing, and for the bug report!