mirror of
https://github.com/adi1090x/rofi.git
synced 2025-12-10 12:22:49 +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"
|
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
|
# Variable passed to rofi
|
||||||
options="$shutdown\n$reboot\n$lock\n$suspend\n$logout"
|
options="$shutdown\n$reboot\n$lock\n$suspend\n$logout"
|
||||||
|
|
||||||
chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)"
|
chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)"
|
||||||
case $chosen in
|
case $chosen in
|
||||||
$shutdown)
|
$shutdown)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "systemctl poweroff"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
$reboot)
|
$reboot)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "systemctl reboot"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
$lock)
|
$lock)
|
||||||
if [[ -f /usr/bin/i3lock ]]; then
|
if [[ -f /usr/bin/i3lock ]]; then
|
||||||
@ -87,31 +93,9 @@ case $chosen in
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
$suspend)
|
$suspend)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "systemctl suspend"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
$logout)
|
$logout)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "loginctl terminate-user $USER"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@ -54,30 +54,36 @@ msg() {
|
|||||||
rofi -theme "$dir/message.rasi" -e "Available Options - yes / y / no / n"
|
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
|
# Variable passed to rofi
|
||||||
options="$shutdown\n$reboot\n$lock\n$suspend\n$logout"
|
options="$shutdown\n$reboot\n$lock\n$suspend\n$logout"
|
||||||
|
|
||||||
chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)"
|
chosen="$(echo -e "$options" | $rofi_command -p "Uptime: $uptime" -dmenu -selected-row 2)"
|
||||||
case $chosen in
|
case $chosen in
|
||||||
$shutdown)
|
$shutdown)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "systemctl poweroff"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
$reboot)
|
$reboot)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "systemctl reboot"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
$lock)
|
$lock)
|
||||||
if [[ -f /usr/bin/i3lock ]]; then
|
if [[ -f /usr/bin/i3lock ]]; then
|
||||||
@ -87,31 +93,9 @@ case $chosen in
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
$suspend)
|
$suspend)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "systemctl suspend"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
$logout)
|
$logout)
|
||||||
ans=$(confirm_exit &)
|
run_response "$(confirm_exit &)" "loginctl terminate-user $USER"
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user