tessen

default description
git clone https://git.awy.one/tessen.git
Log | Files | Refs | README | LICENSE

commit d4315c63b4defca0bbcee0668262cb596256badd
parent cd4608e31b3f4f42891c69e64c7b5f78ca507ff3
Author: Ayush Agarwal <ayush@fastmail.in>
Date:   Wed, 16 Feb 2022 22:31:23 +0530

feat: parse the config file for tessen

the config file also supports pointing rofi and wofi to their config
files which allows for context dependent usage which wasn't possible
earlier (without siginficant annoyance and having to accept arbitrary
input) when environment variables were supported

Diffstat:
Mtessen | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+), 0 deletions(-)

diff --git a/tessen b/tessen @@ -644,6 +644,84 @@ _die() { exit 1 } +# this block of code is needed because we can't source the file and execute +# arbitrary input +parse_config() { + local _opt + while [[ "$#" -gt 0 ]]; do + _opt="$1" + case "$_opt" in + -c | --config) + if [[ "$#" -lt 2 ]] || ! [[ -s "$2" ]]; then + _die "please specify a valid path for the configuration file of tessen" + fi + tsn_config="$2" + shift + ;; + --config=*) + if ! [[ -s "${_opt##--config=}" ]]; then + _die "please specify a valid path for the configuration file of tessen" + fi + tsn_config="${_opt##--config=}" + ;; + esac + shift + done + unset -v _opt + + local line idx key val + local -a config_arr + local config_regex='^[[:alpha:]_]+="[[:alnum:]~_.\/^$|()*?-]+"$' + # in case the user hasn't provided an explicit location, we'll have to check + # if the default file exists before we parse it + if [[ -s "$tsn_config" ]]; then + while read -r line || [[ -n "$line" ]]; do + if [[ "$line" == \#* ]]; then + continue + elif [[ "$line" =~ $config_regex ]]; then + config_arr+=("$line") + fi + done < "$tsn_config" + for idx in "${config_arr[@]}"; do + key="${idx%=*}" + val="${idx#*\"}" + val="${val%*\"}" + # here comes the ladder + if [[ "$key" == "pass_backend" ]]; then + validate_pass_backend "$val" + elif [[ "$key" == "dmenu_backend" ]]; then + validate_dmenu_backend "$val" + elif [[ "$key" == "action" ]]; then + validate_action "$val" + elif [[ "$key" == "rofi_config_file" ]] && [[ "$dmenu_backend" == "rofi" ]]; then + validate_dmenu_backend rofi + dmenu_backend_opts+=("-config $val") + tmp_opts+=("-config $val") + elif [[ "$key" == "wofi_config_file" ]] && [[ "$dmenu_backend" == "wofi" ]]; then + dmenu_backend_opts+=("-c $val") + tmp_opts+=("-c $val") + elif [[ "$key" == "wofi_style_file" ]] && [[ "$dmenu_backend" == "wofi" ]]; then + dmenu_backend_opts+=("-s $val") + tmp_opts+=("-s $val") + elif [[ "$key" == "wofi_color_file" ]] && [[ "$dmenu_backend" == "wofi" ]]; then + dmenu_backend_opts+=("-C $val") + tmp_opts+=("-C $val") + elif [[ "$key" == "userkey" ]]; then + tsn_userkey="$val" + elif [[ "$key" == "urlkey" ]]; then + tsn_urlkey="$val" + elif [[ "$key" == "autotype_key" ]]; then + tsn_autokey="$val" + elif [[ "$key" == "delay" ]]; then + tsn_delay="$val" + elif [[ "$key" == "web_browser" ]] && is_installed "$val"; then + tsn_web_browser="$val" + fi + done + fi + unset -v line key val idx config_arr config_regex +} + main() { local _opt