From bab306d82fafee4ee4c53f24218bb4b928e88a9d Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Thu, 9 Mar 2023 08:39:45 +0700 Subject: [PATCH 1/2] allow null username/password in bw script --- misc/userscripts/qute-bitwarden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/userscripts/qute-bitwarden b/misc/userscripts/qute-bitwarden index f9637bae9..93701eb47 100755 --- a/misc/userscripts/qute-bitwarden +++ b/misc/userscripts/qute-bitwarden @@ -224,7 +224,7 @@ def main(arguments): if len(candidates) == 1: selection = candidates.pop() else: - choices = ['{:s} | {:s}'.format(c['name'], c['login']['username']) for c in candidates] + choices = ['{:s} | {:s}'.format(c['name'] or "?", c['login']['username'] or "?") for c in candidates] choice = dmenu(choices, arguments.dmenu_invocation, arguments.io_encoding) choice_tokens = choice.split('|') choice_name = choice_tokens[0].strip() From 5f87c1aac15585354c10ef004a6e1f4ca5450cf3 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Mon, 3 Mar 2025 09:22:19 +0700 Subject: [PATCH 2/2] Improve code according to suggestions --- misc/userscripts/qute-bitwarden | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/misc/userscripts/qute-bitwarden b/misc/userscripts/qute-bitwarden index 93701eb47..d2aad83ae 100755 --- a/misc/userscripts/qute-bitwarden +++ b/misc/userscripts/qute-bitwarden @@ -224,15 +224,18 @@ def main(arguments): if len(candidates) == 1: selection = candidates.pop() else: - choices = ['{:s} | {:s}'.format(c['name'] or "?", c['login']['username'] or "?") for c in candidates] + choices = { + '{:s} | {:s}'.format( + c['name'] or '?', + c['login']['username'] or '?' + ).strip(): c for c in candidates} + # if two entries have the same string representation, + # it might be impossible to select one of them choice = dmenu(choices, arguments.dmenu_invocation, arguments.io_encoding) - choice_tokens = choice.split('|') - choice_name = choice_tokens[0].strip() - choice_username = choice_tokens[1].strip() - selection = next((c for (i, c) in enumerate(candidates) - if c['name'] == choice_name - and c['login']['username'] == choice_username), - None) + if not choice: + selection = None + else: + selection = choices[choice] # Nothing was selected, simply return if not selection: @@ -243,8 +246,14 @@ def main(arguments): totp = selection['login']['totp'] if arguments.username_only: + if username is None: + stderr('Username is not available') + return ExitCodes.FAILURE fake_key_raw(username) elif arguments.password_only: + if password is None: + stderr('Password is not available') + return ExitCodes.FAILURE fake_key_raw(password) elif arguments.totp_only: # No point in moving it to the clipboard in this case