From 0ef171e6d21f984a19742311a37ea2ccd8d54642 Mon Sep 17 00:00:00 2001 From: Ayush Agarwal Date: Wed, 16 Feb 2022 22:05:31 +0530 Subject: refactor: fix behavior when url is selected if the user selects a url, respond appropriately and change the third menu if the action is default. if it's autotype, open the url. if it's copy, copy the url. if the action is both, open the url and copy it. --- tessen | 56 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/tessen b/tessen index 3ce49c1..6877f77 100755 --- a/tessen +++ b/tessen @@ -313,35 +313,63 @@ key_menu() { "$tsn_userkey") key_action "$tsn_username" ;; password) key_action "$tsn_password" ;; otp) key_otp ;; - "$tsn_urlkey") key_url "${tsn_passdata["$tsn_urlkey"]}" ;; + "$tsn_urlkey") key_action "$tsn_urlkey" ;; *) key_action "${tsn_passdata["$chosen_key"]}" ;; esac } -# THIRD MENU: optional, use 'get_key()' and TESSEN_ACTION to show the option to -# either auto type or copy the selected key +# this function checks the value of tsn_action and decides if the third menu +# should be presented or not +# in case it receives a parameter called "url", autotype becomes equivalent to +# opening the url in the web browser key_action() { local arg="$1" - # POTENTIAL IMPROVEMENT: used 'printf | wtype' instead of 'auto_type()' - # because in all the other cases, 'auto_type()' is meant to exit but we don't - # want to exit here case "$tsn_action" in - autotype) auto_type "$arg" ;; - copy) wld_copy "$arg" ;; - both) - printf "%s" "$arg" | wtype -s "$tsn_delay" - + autotype) + if [[ "$arg" == "$tsn_urlkey" ]]; then + key_open_url || _die + return 0 + fi + auto_type "$arg" + ;; + copy) + if [[ "$arg" == "$tsn_urlkey" ]]; then + wld_copy "$tsn_url" || _die + return 0 + fi wld_copy "$arg" ;; - "") - get_key option - if [[ "$chosen_key" == "$tsn_autokey" ]]; then - auto_type "$arg" + both) + if [[ "$arg" == "$tsn_urlkey" ]]; then + key_open_url + wld_copy "$tsn_url" else + printf "%s" "$arg" | wtype -s "$tsn_delay" - wld_copy "$arg" fi ;; + default) + if [[ "$arg" == "$tsn_urlkey" ]]; then + get_key "$tsn_urlkey" + if [[ "$chosen_key" == "open" ]]; then + key_open_url || _die + return 0 + else + wld_copy "$tsn_url" + fi + else + get_key option + if [[ "$chosen_key" == "$tsn_autokey" ]]; then + auto_type "$arg" + else + wld_copy "$arg" + fi + fi + ;; esac + + unset -v arg } # THIRD MENU: optional, this function is used if an 'otpauth://' URI is found -- cgit v1.2.3