commit ba7469611efcd2d172944a2a6badb041f29c9d4e parent 55c550b05dc8401a3862b80e564197de37ddb772 Author: Ayush Agarwal <ayush@fastmail.in> Date: Wed, 8 Sep 2021 03:55:39 +0530 some code refactoring done turns out, we don't need `choice_data_copy` and `choice_data_autotype` but only a single `choice_data` function thanks to array slicing and a if-then conditional Diffstat:
| M | tessen | | | 34 | ++++++++++------------------------ |
1 file changed, 10 insertions(+), 24 deletions(-)
diff --git a/tessen b/tessen @@ -63,32 +63,19 @@ get_pass_data() { done } -# get the key that the user chooses to copy -choice_data_copy() { - local ch flag +# get the key that the user chooses to copy or autotype +choice_data() { + local ch flag choice_arr flag="" + choice_arr=("autotype" "username" "password" "${!PASSDATA_ARR[@]}") - CHOICE="$(printf '%s\n' "username" "password" "${!PASSDATA_ARR[@]}" | "${BACKEND[@]}")" - - for ch in "username" "password" "${!PASSDATA_ARR[@]}"; do - if [[ "$CHOICE" == "$ch" ]]; then - flag=1 - fi - done - - if [[ "$flag" -ne 1 ]]; then - exit 1 + if [[ "$WTYPE" -eq 1 ]]; then + CHOICE="$(printf '%s\n' "${choice_arr[@]}" | "${BACKEND[@]}")" + else + CHOICE="$(printf '%s\n' "${choice_arr[@]:1}" | "${BACKEND[@]}")" fi -} - -# get the key that the user chooses to autotype -choice_data_autotype() { - local ch flag - flag="" - - CHOICE="$(printf '%s\n' "autotype" "username" "password" "${!PASSDATA_ARR[@]}" | "${BACKEND[@]}")" - for ch in "autotype" "username" "password" "${!PASSDATA_ARR[@]}"; do + for ch in "${choice_arr[@]}"; do if [[ "$CHOICE" == "$ch" ]]; then flag=1 fi @@ -244,12 +231,11 @@ main() { trap 'die' EXIT TERM get_pass_file get_pass_data + choice_data if [[ "$WTYPE" -eq 1 ]]; then - choice_data_autotype key_menu_autotype else - choice_data_copy key_menu_copy fi trap - EXIT TERM