summaryrefslogtreecommitdiff
path: root/tessen
diff options
context:
space:
mode:
authorAyush Agarwal <ayush@fastmail.in>2021-11-14 14:10:54 +0530
committerAyush Agarwal <ayush@fastmail.in>2021-11-14 14:10:54 +0530
commitc6272fae4eaa724a59c096d742672f4edadd8523 (patch)
tree6ae0c680462f9bef4c763bf4c6ebf252d51650c8 /tessen
parent70fdbf205a7520ecd885534adcea539b05e587d6 (diff)
refactor: make the key selection modular
The `key_menu()` function will now handle different types of keys using case and specific functions instead of complex if-else monstrosity. feat: continue to implement features explained in 9511148
Diffstat (limited to 'tessen')
-rwxr-xr-xtessen65
1 files changed, 33 insertions, 32 deletions
diff --git a/tessen b/tessen
index ee0a5ff..ee6b74c 100755
--- a/tessen
+++ b/tessen
@@ -130,40 +130,41 @@ get_key() {
fi
}
-# the 2nd, and possibly 3rd, stage of the menu
+# SECOND MENU: use 'get_key()' to show a list of possible keys to choose from
key_menu() {
- local tmp_key
-
- get_key pass_key_list
-
- if [[ "$chosen_key" == "autotype username and password" ]]; then
- auto_type username_password
- exit 0
- fi
+ get_key key_list
+
+ case "$chosen_key" in
+ "$tsn_autokey") auto_type_def ;;
+ "$tsn_userkey") key_action "$tsn_username" ;;
+ password) key_action "$tsn_password" ;;
+ otp) key_otp ;;
+ "$tsn_urlkey") key_url "${tsn_passdata["$tsn_urlkey"]}" ;;
+ *) key_action "${tsn_passdata["$chosen_key"]}" ;;
+ esac
+}
- if [[ "$tsn_action" == "autotype" ]]; then
- auto_type "$chosen_key"
- exit 0
- elif [[ "$tsn_action" == "copy" ]]; then
- wld_copy "$chosen_key"
- elif [[ "$tsn_action" == "both" ]]; then
- auto_type "$chosen_key"
- wld_copy "$chosen_key"
- elif [[ -z "$tsn_action" ]]; then
- tmp_key="$chosen_key"
- get_key opt_key_list
- if [[ "$chosen_key" == "autotype" ]]; then
- auto_type "$tmp_key"
- exit 0
- elif [[ "$chosen_key" == "copy" ]]; then
- wld_copy "$tmp_key"
- else
- exit 1
- fi
- else
- printf '%s\n' "Please specify a valid option: autotype|copy|both" >&2
- exit 1
- fi
+# THIRD MENU: optional, use 'get_key()' and TESSEN_ACTION to show the option to
+# either auto type or copy the selected key
+key_action() {
+ local arg="$1"
+
+ case "$tsn_action" in
+ autotype) auto_type "$arg" ;;
+ copy) wld_copy "$arg" ;;
+ both)
+ printf "%s" "$arg" | wtype -s "$tsn_delay" -
+ wld_copy "$arg"
+ ;;
+ "")
+ get_key option
+ if [[ "$chosen_key" == "$tsn_autokey" ]]; then
+ auto_type "$arg"
+ else
+ wld_copy "$arg"
+ fi
+ ;;
+ esac
}
auto_type() {