mirror of
https://github.com/adi1090x/rofi.git
synced 2025-12-10 04:22:48 +01:00
reduce code duplication
This commit is contained in:
parent
aba9eb3d1a
commit
3c49b3d6fa
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user