neodotfiles/user/.config/suckless/dmenu/scripts/dmenu_power

96 lines
3.2 KiB
Text
Raw Normal View History

2022-12-20 00:15:21 +00:00
#!/usr/bin/env bash
# ***This script was made by Clay Gomera (Drake)***
# - Description: A simple power menu dmenu script
2023-09-04 17:36:18 +00:00
# - Dependencies: dmenu, power-profiles-daemon, slock
2022-12-20 00:15:21 +00:00
2023-09-04 17:36:18 +00:00
#######################
2023-10-03 14:40:20 +00:00
## Main manu options ##
2023-09-04 17:36:18 +00:00
#######################
2023-06-24 17:00:22 +00:00
option1=" Logout"
option2=" Reboot"
option3=" Power off"
option4="󰒲 Suspend"
option5=" Lock"
option6=" Change power profile"
2023-10-03 14:40:20 +00:00
option7="󱎘 Exit"
2022-12-20 00:15:21 +00:00
options="$option1\n$option2\n$option3\n$option4\n$option5\n$option6\n$option7"
2023-10-03 14:40:20 +00:00
####################################
## Power profiles submenu options ##
####################################
2023-06-24 17:00:22 +00:00
pwr1="󰓅 Performance"
pwr2="󰾅 Balanced"
pwr3="󰾆 Power Saver"
pwr4=" Cancel"
2022-12-20 00:15:21 +00:00
pwrs="$pwr1\n$pwr2\n$pwr3\n$pwr4"
2023-10-03 14:40:20 +00:00
#####
## This variable will store the current power profile
#####
currentpwr=$(powerprofilesctl get)
2023-09-04 17:36:18 +00:00
##########
## main ##
##########
action=$(echo -e "$options" | dmenu -i -p " Power Options"); # main menu prompt
2022-12-20 00:15:21 +00:00
case "$action" in
2023-09-04 17:36:18 +00:00
"$option1")
pkill X; # killing X will result in a logout
;;
"$option2")
systemctl reboot || loginctl reboot;
;;
"$option3")
systemctl poweroff || loginctl poweroff;
;;
"$option4")
slock systemctl suspend || slock loginctl suspend;
;;
"$option5")
slock;
;;
"$option6")
2023-10-03 14:40:20 +00:00
#####
## These conditions will be used for the prompt
#####
if [ "$currentpwr" = "performance" ]; then
currentpwr="$pwr1";
2023-06-24 17:00:22 +00:00
elif [ "$currentpwr" = "balanced" ]; then
2023-10-03 14:40:20 +00:00
currentpwr="$pwr2";
2023-06-24 17:00:22 +00:00
elif [ "$currentpwr" = "power-saver" ]; then
2023-10-03 14:40:20 +00:00
currentpwr="$pwr3";
2023-06-24 17:00:22 +00:00
fi
2023-10-03 14:40:20 +00:00
pwraction=$(echo -e "$pwrs" | dmenu -l 6 -i -p " Power Profile Menu - Currently set to: $currentpwr") # power profiles submenu prompt
2022-12-20 00:15:21 +00:00
case "$pwraction" in
2023-09-04 17:36:18 +00:00
"$pwr1")
2023-10-03 14:40:20 +00:00
if [ "$currentpwr" = "$pwr1" ]; then # if the power profile is already set to performance
notify-send "The power profile is already set to performance";
exit 1;
else
powerprofilesctl set performance && notify-send "Power profile switched to performance"; # if not, set the powerprofile to performance
fi
2023-09-04 17:36:18 +00:00
;;
"$pwr2")
2023-10-03 14:40:20 +00:00
if [ "$currentpwr" = "$pwr2" ]; then # if the power profile is already set to balanced
notify-send "The power profile is already set to balanced";
exit 1;
else
powerprofilesctl set balanced && notify-send "Power profile switched to balanced"; # if not, set the powerprofile to balanced
fi
2023-09-04 17:36:18 +00:00
;;
"$pwr3")
2023-10-03 14:40:20 +00:00
if [ "$currentpwr" = "$pwr3" ]; then # if the power profile is already set to power saver
notify-send "The power profile is already set to power saver";
exit 1;
else
powerprofilesctl set power-saver && notify-send "Power profile switched to power saver"; # if not, set the powerprofile to power saver
fi
2023-09-04 17:36:18 +00:00
;;
"$pwr4")
2023-10-03 14:40:20 +00:00
exit 0;
esac;;
2023-09-04 17:36:18 +00:00
"$option7")
2023-10-03 14:40:20 +00:00
exit 0;
2022-12-20 00:15:21 +00:00
esac