From cd4608e31b3f4f42891c69e64c7b5f78ca507ff3 Mon Sep 17 00:00:00 2001 From: Ayush Agarwal Date: Wed, 16 Feb 2022 22:27:10 +0530 Subject: refactor: better response when validating action with this change, an action can't be selected if it's not possible and the best available choice should be selected automatically in case no action is provided. --- tessen | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/tessen b/tessen index 66eecfc..46bb24d 100755 --- a/tessen +++ b/tessen @@ -594,10 +594,39 @@ validate_cliptime() { validate_action() { case "$1" in - autotype) readonly tsn_action="autotype" ;; - copy) readonly tsn_action="copy" ;; - both) readonly tsn_action="both" ;; - "") readonly tsn_action="" ;; + autotype) + if ! is_installed "wtype"; then + _die "wtype is not installed, unable to autotype pass data" + fi + tsn_action="autotype" + ;; + copy) + if ! is_installed "wl-copy"; then + _die "wl-clipboard is not installed, unable to copy-paste pass data" + fi + tsn_action="copy" + ;; + both) + if ! is_installed "wtype"; then + _die "wtype is not installed, unable to autotype pass data" + elif ! is_installed "wl-copy"; then + _die "wl-clipboard is not installed, unable to copy-paste pass data" + fi + tsn_action="both" + ;; + default) + if is_installed "wtype" && is_installed "wl-copy"; then + tsn_action="default" + elif is_installed "wtype" && ! is_installed "wl-copy"; then + printf "%s\n" "wl-clipboard is not installed, unable to copy-paste pass data" >&2 + tsn_action="autotype" + elif ! is_installed "wtype" && is_installed "wl-copy"; then + printf "%s\n" "wtype is not installed, unable to autotype pass data" >&2 + tsn_action="copy" + elif ! is_installed "wtype" && ! is_installed "wl-copy"; then + _die "please install at least one the following backends to use tessen: wtype | wl-clipboard " + fi + ;; *) _die "please specify a valid action: autotype | copy | both" ;; esac } -- cgit v1.2.3