summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Wilken2023-12-11 21:47:24 +0100
committerTimo Wilken2023-12-11 21:47:24 +0100
commit518ce823220bc9908be1fe93e375a922cce6b588 (patch)
tree056ab9aa6380656894efecc29b0a1cd87ca6d57e
parent48874c00aed86aaff18d909d60dd0f3f0a6c0ba8 (diff)
Customise passmenu prompt to show what will be typed
Also, document an older option and switch on `sh -u` safety option.
-rwxr-xr-xtw/home/files/passmenu22
1 files 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 <tab> 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