From 32df042edcb5edaeca5e4ae273e22f9cfb6ad86e Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 9 Aug 2023 21:18:22 +0200 Subject: Factor out most common operations into functions. --- rofi-pass | 86 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/rofi-pass b/rofi-pass index 5dba345..88d9a3f 100755 --- a/rofi-pass +++ b/rofi-pass @@ -9,14 +9,6 @@ _rofi () { rofi -no-auto-select -i "$@" } -_pwgen () { - pwgen -y "$@" -} - -_image_viewer () { - feh - -} - config_dir=${XDG_CONFIG_HOME:-$HOME/.config} cache_dir=${XDG_CACHE_HOME:-$HOME/.cache} @@ -83,6 +75,42 @@ esac # Safe permissions umask 077 +_exists () { + type -P "$1" >/dev/null 2>&1 ; +} + + _pwgen () { + if _exists pwgen ; then + pwgen -y "$@" | cat + else + tr -dc '[:graph:]' "$cache_dir/rofi-pass/last_used" @@ -189,11 +214,7 @@ autopass () { ${do_press_key} Return fi - if [[ $backend == "xdotool" ]]; then - xset r "$x_repeat_enabled" - unset x_repeat_enabled - fi - + _restore_auto_repeat clearUp } @@ -233,28 +254,18 @@ openURL () { typeUser () { checkIfPass - if [[ $backend == "xdotool" ]]; then - x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}') - xset r off - fi + _save_auto_repeat printf '%s' "${stuff[${USERNAME_field}]}" | ${do_type} - if [[ $backend == "xdotool" ]]; then - xset r "$x_repeat_enabled" - unset x_repeat_enabled - fi - + _restore_auto_repeat clearUp } typePass () { checkIfPass - if [[ $backend == "xdotool" ]]; then - x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}') - xset r off - fi + _save_auto_repeat printf '%s' "${password}" | ${do_type} @@ -272,10 +283,7 @@ typePass () { fi fi - if [[ $backend == "xdotool" ]]; then - xset r "$x_repeat_enabled" - unset x_repeat_enabled - fi + _restore_auto_repeat clearUp } @@ -284,10 +292,7 @@ typeField () { checkIfPass local to_type - if [[ $backend == "xdotool" ]]; then - x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}') - xset r off - fi + _save_auto_repeat case $typefield in "OTP") to_type="$(generateOTP)" ;; @@ -296,10 +301,7 @@ typeField () { printf '%s' "$to_type" | ${do_type} - if [[ $backend == "xdotool" ]]; then - xset r "$x_repeat_enabled" - unset x_repeat_enabled - fi + _restore_auto_repeat unset to_type -- cgit