From 518ce823220bc9908be1fe93e375a922cce6b588 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Mon, 11 Dec 2023 21:47:24 +0100 Subject: Customise passmenu prompt to show what will be typed Also, document an older option and switch on `sh -u` safety option. --- tw/home/files/passmenu | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tw/home/files/passmenu b/tw/home/files/passmenu index abeb98fb..9bf7f7e3 100755 --- a/tw/home/files/passmenu +++ b/tw/home/files/passmenu @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh -eu usage() { cat << EOF @@ -6,6 +6,7 @@ $(basename "$0") [-c | -p | -a] -c, --clip copy the user-selected password to the clipboard -p, --type-pass auto-type the user-selected password only + -o, --type-otp auto-type the user-selected six-digit OTP code -a, --type-all auto-type the user-selected username password -h, --help show this help message and exit -v, --version show the program version number and exit @@ -19,7 +20,7 @@ Abnormal exit codes: 2 invalid command-line argument 3 internal error -(C) 2019-2022 Timo Wilken; MIT Licence. +(C) 2019-2023 Timo Wilken; MIT Licence. Adapted from https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu. EOF } @@ -29,7 +30,8 @@ version() { # 1.0.0 (2019-??-??) initial version # 1.0.1 (2022-07-17) script formatting; throw away passwords asap # 1.0.2 (2022-10-??) remove fix_xdotool; this should be done on login - echo "$(basename "$0") 1.0.2" + # 1.0.3 (2023-12-11) customise prompt to show what will be typed + echo "$(basename "$0") 1.0.3" } password_names() { @@ -46,13 +48,12 @@ type_stdin() { } ## Command-line arguments -mode=clip while [ $# -gt 0 ]; do case "$1" in - -o|--type-otp) mode=type-otp; shift;; - -p|--type-pass) mode=type-pass; shift;; - -a|--type-all) mode=type-all; shift;; - -c|--clip) mode=clip; shift;; + -o|--type-otp) mode=type-otp prompt=OTP; shift;; + -p|--type-pass) mode=type-pass prompt=Password; shift;; + -a|--type-all) mode=type-all prompt=Login; shift;; + -c|--clip) mode=clip prompt=Copy; shift;; -h|--help) usage; exit;; -v|--version) version; exit;; @@ -62,9 +63,10 @@ while [ $# -gt 0 ]; do exit 2;; esac done +: "${mode=clip}" "${prompt=Copy}" ## Password selection menu -password_name=$(password_names | rofi -dmenu -i -p Password -no-custom) +password_name=$(password_names | rofi -dmenu -i -p "$prompt" -no-custom) [ -n "$password_name" ] || exit 1 ## Password typing @@ -76,7 +78,7 @@ case "$mode" in type-otp) pass otp "$password_name" | type_stdin;; - type-*) + type-pass|type-all) entry=$(pass show "$password_name") if [ "$mode" = type-all ]; then echo "$entry" | extract_key username | type_stdin -- cgit v1.2.3