commit c10030ae7816a6ef7a5612f038f2c7ec454a8c18
parent 06e705fc593b5de63a37f04c210d7c7768884e12
Author: Jerzy Drozdz <jerzy.drozdz@jdsieci.pl>
Date: Mon, 24 Jan 2022 07:01:08 +0100
userkey search uses regex to find field (#11)
* userkey search uses regex to find field
* Changed userkey default value to "user"
* First matched entry will be set as tsn_username
* Update to man page
* Fixed setting userkey
* Fixed typo
Diffstat:
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/man/tessen.1.scd b/man/tessen.1.scd
@@ -81,7 +81,8 @@ URI. However, if a key called 'password' is present, it will be ignored.
If a key called 'user' is present, its value will be the default username
instead of the basename of the selected file. This key can be modified using the
-*TESSEN_USERKEY* environment variable.
+*TESSEN_USERKEY* environment variable. If entries in password store use
+different keys for specifying user names regular expression can be used.
If a key called 'url' is present, an option to open the value of the 'url' key
in the default web browser will be shown instead of auto type. This becomes the
diff --git a/tessen b/tessen
@@ -22,7 +22,8 @@ readonly -a tsn_known_backends=('bemenu' 'fuzzel' 'rofi' 'wofi')
tsn_backend="${TESSEN_BACKEND-}"
tsn_backend_opts=()
tsn_action="${TESSEN_ACTION-}"
-tsn_userkey="${TESSEN_USERKEY:-user}"
+tsn_userkey_regex="${TESSEN_USERKEY:-user}"
+tsn_userkey="user"
tsn_urlkey="${TESSEN_URLKEY:-url}"
tsn_autokey="${TESSEN_AUTOKEY:-autotype}"
tsn_autotype=""
@@ -85,8 +86,9 @@ get_pass_data() {
# keys with the case insensitive name 'password' are ignored
if [[ "${key,,}" == "password" ]]; then
continue
- elif [[ "${key,,}" == "$tsn_userkey" ]]; then
+ elif [[ -z "${tsn_username}" ]] && [[ "${key,,}" =~ ^${tsn_userkey_regex}$ ]]; then
tsn_username="$val"
+ tsn_userkey="${key,,}"
elif [[ "${key,,}" == "$tsn_autokey" ]]; then
tsn_autotype="$val"
elif [[ "$idx" =~ $otp_regex ]]; then
@@ -96,7 +98,7 @@ get_pass_data() {
fi
done
- # if $tsn_userkey isn't found, use the basename of file as username
+ # if $tsn_userkey_regex isn't found, use the basename of file as username
if [[ -z "$tsn_username" ]]; then
tsn_username="${tsn_passfile##*/}"
fi