commit e4f3c5a6d1ac2bcba5c28b4dd9a46a5b6a08954b
parent cbb35e4305cfd62d7d0bbc9d443fb1f96c21a2de
Author: Ayush Agarwal <ayush@fastmail.in>
Date: Mon, 20 Sep 2021 00:55:56 +0530
fix the backend validation logic
This might be a hack but I had to figure out how to work with the
following
- if no backend choice is given, assume bemenu
- if the user sets the TESSEN_BACKEND env var, use that
- if the user provides the `-b` flag at runtime, use that above all else
I've already assumed bemenu by default in the list of global variables.
However, figuring out how to prefer the command line flag over the env
var was a bit tricky I guess.
I changed the `validate_backend` function to always assign both backend
global variables as readonly and this function is always called if the
user provides a `-b` flag at runtime. If he doesn't though, I can safely
use the unset condition on the BACKEND_OPTS variable, instead of
BACKEND, since it has not been assigned anyways. If it can be unset, it
means it hasn't been made readonly, which means `-b` wasn't provided. We
can call the `validate_backend` function to do what we wanted.
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tessen b/tessen
@@ -184,12 +184,15 @@ print_help() {
validate_backend() {
if [[ "$BACKEND" == "bemenu" ]]; then
bmn_opt=("-i -l 10 -w --scrollbar=autohide -n")
- readonly BEMENU_OPTS="${BEMENU_OPTS:-${bmn_opt[*]}}"
- export BEMENU_OPTS
+ export BEMENU_OPTS="${BEMENU_OPTS:-${bmn_opt[*]}}"
+ readonly BACKEND="bemenu"
+ readonly BACKEND_OPTS=""
unset -v bmn_opt
elif [[ "$BACKEND" == "rofi" ]]; then
- BACKEND=(rofi -dmenu)
+ readonly BACKEND="rofi"
+ readonly BACKEND_OPTS="-dmenu"
else
+ printf '%s\n' "Please specify a backend: bemenu|rofi" >&2
exit 1
fi
}
@@ -282,7 +285,9 @@ main() {
done
unset -v _opt
- validate_backend
+ if unset -v BACKEND_OPTS 2> /dev/null; then
+ validate_backend
+ fi
validate_clip_time
readonly WTYPE