diff --git a/1080p/powermenu/powermenu.sh b/1080p/powermenu/powermenu.sh index 9b444f4..5a0e902 100755 --- a/1080p/powermenu/powermenu.sh +++ b/1080p/powermenu/powermenu.sh @@ -54,30 +54,36 @@ msg() { rofi -theme "$dir/message.rasi" -e "Available Options - yes / y / no / n" } +run_response() { + local response="$1" + local run="$2" + + case "$response" in + YES|yes|[yY]) + if [[ "$run" == "systemctl suspend" ]]; then + mpc -q pause + amixer set Master mute + $run + else + $run + fi + ;; + + NO|no|[Nn]) exit 0; ;; + *) msg ; ;; + esac +} + # Variable passed to rofi options="$shutdown\n$reboot\n$lock\n$suspend\n$logout" chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)" case $chosen in $shutdown) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - systemctl poweroff - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "systemctl poweroff" ;; $reboot) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - systemctl reboot - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "systemctl reboot" ;; $lock) if [[ -f /usr/bin/i3lock ]]; then @@ -87,31 +93,9 @@ case $chosen in fi ;; $suspend) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - mpc -q pause - amixer set Master mute - systemctl suspend - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "systemctl suspend" ;; $logout) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - if [[ "$DESKTOP_SESSION" == "Openbox" ]]; then - openbox --exit - elif [[ "$DESKTOP_SESSION" == "bspwm" ]]; then - bspc quit - elif [[ "$DESKTOP_SESSION" == "i3" ]]; then - i3-msg exit - fi - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "loginctl terminate-user $USER" ;; esac diff --git a/720p/powermenu/powermenu.sh b/720p/powermenu/powermenu.sh index 9b444f4..5a0e902 100755 --- a/720p/powermenu/powermenu.sh +++ b/720p/powermenu/powermenu.sh @@ -54,30 +54,36 @@ msg() { rofi -theme "$dir/message.rasi" -e "Available Options - yes / y / no / n" } +run_response() { + local response="$1" + local run="$2" + + case "$response" in + YES|yes|[yY]) + if [[ "$run" == "systemctl suspend" ]]; then + mpc -q pause + amixer set Master mute + $run + else + $run + fi + ;; + + NO|no|[Nn]) exit 0; ;; + *) msg ; ;; + esac +} + # Variable passed to rofi options="$shutdown\n$reboot\n$lock\n$suspend\n$logout" chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)" case $chosen in $shutdown) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - systemctl poweroff - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "systemctl poweroff" ;; $reboot) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - systemctl reboot - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "systemctl reboot" ;; $lock) if [[ -f /usr/bin/i3lock ]]; then @@ -87,31 +93,9 @@ case $chosen in fi ;; $suspend) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - mpc -q pause - amixer set Master mute - systemctl suspend - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "systemctl suspend" ;; $logout) - ans=$(confirm_exit &) - if [[ $ans == "yes" || $ans == "YES" || $ans == "y" || $ans == "Y" ]]; then - if [[ "$DESKTOP_SESSION" == "Openbox" ]]; then - openbox --exit - elif [[ "$DESKTOP_SESSION" == "bspwm" ]]; then - bspc quit - elif [[ "$DESKTOP_SESSION" == "i3" ]]; then - i3-msg exit - fi - elif [[ $ans == "no" || $ans == "NO" || $ans == "n" || $ans == "N" ]]; then - exit 0 - else - msg - fi + run_response "$(confirm_exit &)" "loginctl terminate-user $USER" ;; esac