diff options
author | Ayush Agarwal <ayush@fastmail.in> | 2022-02-16 23:50:47 +0530 |
---|---|---|
committer | Ayush Agarwal <ayush@fastmail.in> | 2022-02-16 23:50:47 +0530 |
commit | 0fde1edf28e0527d5d8e4eabb0bdcc2833eba187 (patch) | |
tree | f8e2d434760564a57d63b2169794c0bfd6fae815 | |
parent | b4422c24d9695bdd642fdbbea7206649c4fd89a3 (diff) |
refactor: find default pass and dmenu backends
if the user doesn't provide any input via arguments or config file, try
to setup sane defaults
-rwxr-xr-x | tessen | 46 |
1 files changed, 43 insertions, 3 deletions
@@ -491,9 +491,8 @@ wld_copy() { unset -v tsn_passfile tsn_passdata tsn_username tsn_password chosen_key } - -is_installed() { - if command -v "${1%% *}" > /dev/null 2>&1; then +are_digits() { + if [[ "$1" =~ ^[[:digit:]]+$ ]]; then return 0 else return 1 @@ -597,6 +596,47 @@ validate_action() { esac } +find_pass_backend() { + local -a tmp_pass_arr=('pass' 'gopass') + local idx + + for idx in "${tmp_pass_arr[@]}"; do + if is_installed "$idx"; then + pass_backend="$idx" + break + fi + done + if [[ -z "$pass_backend" ]]; then + _die "please install a valid password store backend: pass | gopass" + fi + + unset -v idx tmp_pass_arr +} + +find_dmenu_backend() { + local -a tmp_dmenu_arr=('rofi' 'fuzzel' 'bemenu' 'wofi') + local idx + + for idx in "${tmp_dmenu_arr[@]}"; do + if is_installed "$idx"; then + dmenu_backend="$idx" + break + fi + done + if [[ -z "$dmenu_backend" ]]; then + _die "please install a valid dmenu backend: rofi | fuzzel | bemenu | wofi" + fi + unset -v idx tmp_dmenu_arr +} + +is_installed() { + if command -v "$1" > /dev/null 2>&1; then + return 0 + else + return 1 + fi +} + _clear() { if [[ "$tsn_action" =~ ^(copy|both|default)$ ]]; then wl-copy --clear |