dotfiles/hypr/scripts/wofi_powermenu
2024-10-23 11:53:39 +02:00

86 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
## Copyright (C) 2020-2024 Aditya Shakya <adi1090x@gmail.com>
##
## Wofi Powermenu
## Files
CONFIG="$HOME/.config/hypr/wofi/config"
STYLE="$HOME/.config/hypr/wofi/style.css"
## Wofi Command
wofi_command="wofi --show dmenu \
--conf ${CONFIG} --style ${STYLE} \
--width=300 --height=215 \
--cache-file=/dev/null \
--hide-scroll --no-actions \
--define=matching=fuzzy"
uptime=$(uptime -p | sed -e 's/up //g')
## Entries
shutdown=" Shutdown"
reboot=" Restart"
lock=" Lock"
suspend=" Sleep"
logout=" Logout"
# Ask for confirmation
cdialog () {
yad --title='Confirm?' --borders=15 --center --fixed --undecorated --button=Yes:0 --button=No:1 --text="Are you sure?" --text-align=center
}
# Variable passed to rofi
open_menu () {
options="$lock\n$suspend\n$logout\n$reboot\n$shutdown"
chosen="$(echo -e "$options" | $wofi_command --prompt "UP - $uptime")"
case $chosen in
$shutdown)
cdialog
if [[ "$?" == 0 ]]; then
systemctl poweroff
else
exit
fi
;;
$reboot)
cdialog
if [[ "$?" == 0 ]]; then
systemctl reboot
else
exit
fi
;;
$lock)
~/.config/hypr/scripts/lockscreen
;;
$suspend)
cdialog
if [[ "$?" == 0 ]]; then
mpc -q pause
pulsemixer --mute
~/.config/hypr/scripts/lockscreen
systemctl suspend
else
exit
fi
;;
$logout)
cdialog
if [[ "$?" == 0 ]]; then
hyprctl dispatch exit 0
else
exit
fi
;;
esac
}
if [[ ! `pidof wofi` ]]; then
open_menu
else
pkill wofi
fi