From c0771567aca0f4fcaef513fcfeb016e6cb2cae64 Mon Sep 17 00:00:00 2001 From: Michael Erdely Date: Wed, 24 Nov 2021 23:26:31 -0500 Subject: [PATCH 1/2] Show password prompt on a single line (due to rofi code change) Add ability to copy URI for an item with Alt+4 --- bwmenu | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/bwmenu b/bwmenu index a9c342d..3f86ed9 100755 --- a/bwmenu +++ b/bwmenu @@ -33,6 +33,7 @@ KB_LOCK="Alt+L" KB_TYPEALL="Alt+1" KB_TYPEUSER="Alt+2" KB_TYPEPASS="Alt+3" +KB_URICOPY="Alt+4" # Item type classification TYPE_LOGIN=1 @@ -49,7 +50,7 @@ DIR="$(dirname "$(readlink -f "$0")")" source "$DIR/lib-bwmenu" ask_password() { - mpw=$(printf '' | rofi -dmenu -p "Master Password" -password -lines 0) || exit $? + mpw=$(printf '' | rofi -dmenu -p "Master Password" -password -l 0) || exit $? echo "$mpw" | bw unlock 2>/dev/null | grep 'export' | sed -E 's/.*export BW_SESSION="(.*==)"$/\1/' || exit_error $? "Could not unlock vault" } @@ -98,19 +99,23 @@ rofi_menu() { -kb-custom-4 $KB_FOLDERSELECT -kb-custom-8 $KB_TOTPCOPY -kb-custom-9 $KB_LOCK + -kb-custom-10 $KB_URICOPY ) msg="$KB_SYNC: sync | $KB_URLSEARCH: urls | $KB_NAMESEARCH: names | $KB_FOLDERSELECT: folders | $KB_TOTPCOPY: totp | $KB_LOCK: lock" - [[ ! -z "$AUTOTYPE_MODE" ]] && { + if [[ ! -z "$AUTOTYPE_MODE" ]]; then actions+=( -kb-custom-5 $KB_TYPEALL -kb-custom-6 $KB_TYPEUSER -kb-custom-7 $KB_TYPEPASS ) msg+=" -$KB_TYPEALL: Type all | $KB_TYPEUSER: Type user | $KB_TYPEPASS: Type pass" - } +$KB_TYPEALL: Type all | $KB_TYPEUSER: Type user | $KB_TYPEPASS: Type pass | $KB_URICOPY: Copy uri" + else + msg+=" +$KB_URICOPY: Copy uri" + fi rofi -dmenu -p 'Name' \ -i -no-custom \ @@ -204,6 +209,7 @@ on_rofi_exit() { 13) show_folders;; 17) copy_totp "$2";; 18) lock_vault;; + 19) copy_uri "$2";; 14) auto_type all "$2";; 15) auto_type username "$2";; 16) auto_type password "$2";; @@ -359,6 +365,24 @@ copy_totp() { fi } +# Copy the URL +# $1: item array +copy_uri() { + if not_unique "$1"; then + ITEMS="$item_array" + show_full_items + else + id=$(echo "$1" | jq -r ".[0].id") + + if ! uri=$(bw --session "$BW_HASH" get uri "$id"); then + exit_error 1 "$uri" + fi + + echo -n "$uri" | clipboard-set + notify-send "URI Copied" + fi +} + # Lock the vault by purging the key used to store the session hash lock_vault() { keyctl purge user bw_session &>/dev/null @@ -440,6 +464,7 @@ Quick Actions: $KB_TYPEALL Autotype the username and password [needs xdotool or ydotool] $KB_TYPEUSER Autotype the username [needs xdotool or ydotool] $KB_TYPEPASS Autotype the password [needs xdotool or ydotool] + $KB_URICOPY Copy the URL $KB_LOCK Lock your vault From 9be384cb1884811b8ab3e05cde30a8eca79a9d62 Mon Sep 17 00:00:00 2001 From: Michael Erdely Date: Wed, 24 Nov 2021 23:31:18 -0500 Subject: [PATCH 2/2] From https://github.com/mattydebie/bitwarden-rofi/pull/55/commits/bd3aa2261c9b6453faefd73dd4829ffbb73c0b41 Copy TOTP when typing password or username/password Also make sure $message is defined before publishing a message with it --- bwmenu | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bwmenu b/bwmenu index 3f86ed9..3f684e5 100755 --- a/bwmenu +++ b/bwmenu @@ -84,7 +84,7 @@ exit_error() { local code="$1" local message="$2" - rofi -e "$message" + [ $message ] && rofi -e "$message" exit "$code" } @@ -231,12 +231,14 @@ auto_type() { type_word "$(echo "$2" | jq -r '.[0].login.username')" type_tab type_word "$(echo "$2" | jq -r '.[0].login.password')" + copy_totp "$2" ;; username) type_word "$(echo "$2" | jq -r '.[0].login.username')" ;; password) type_word "$(echo "$2" | jq -r '.[0].login.password')" + copy_totp "$2" ;; esac fi