summaryrefslogtreecommitdiff
path: root/tessen
diff options
context:
space:
mode:
authorAyush Agarwal <ayush@fastmail.in>2022-02-16 22:27:10 +0530
committerAyush Agarwal <ayush@fastmail.in>2022-02-16 22:27:10 +0530
commitcd4608e31b3f4f42891c69e64c7b5f78ca507ff3 (patch)
treeb1c8857f77923aad2b6106dce3dd687d8b66362e /tessen
parent3239d30b10cf4162f23a58e78513818682c68638 (diff)
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.
Diffstat (limited to 'tessen')
-rwxr-xr-xtessen37
1 files 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
}