113 lines
3.3 KiB
Bash
Executable file
113 lines
3.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# *** Script by Clay Gomera (Drake) ***
|
|
# Description: A dmenu script for managing power options
|
|
# Dependencies: dmenu, powerprofilesctl, slock, systemctl, notify-send
|
|
|
|
# Main menu options
|
|
option1=" Logout"
|
|
option2=" Reboot"
|
|
option3=" Power off"
|
|
option4=" Suspend"
|
|
option5=" Lock"
|
|
option6=" Change power profile"
|
|
option7=" Exit"
|
|
options="$option1\n$option2\n$option3\n$option4\n$option5\n$option6\n$option7"
|
|
|
|
# Power profiles submenu options
|
|
pwr1=" Performance"
|
|
pwr2=" Balanced"
|
|
pwr3=" Power Saver"
|
|
pwr4=" Cancel"
|
|
pwrs="$pwr1\n$pwr2\n$pwr3\n$pwr4"
|
|
|
|
# Store the current power profile
|
|
currentpwr=$(powerprofilesctl get)
|
|
|
|
# Store the current wallpaper set by feh
|
|
currentwall=$(tail --lines=1 "$HOME/.fehbg" | awk '{print $4}' | sed "s/'//g")
|
|
|
|
# Ask user for confirmation with yes/no options
|
|
confirm_action() {
|
|
local prompt="$1"
|
|
echo -e " Yes\n No" | dmenu -l 2 -i -p "$prompt" | grep -q " Yes"
|
|
}
|
|
|
|
# Show main menu and get user action
|
|
action=$(echo -e "$options" | dmenu -i -p " Power Options")
|
|
if [ -z "$action" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
case "$action" in
|
|
"$option1")
|
|
if confirm_action " Are you sure you want to logout?"; then
|
|
pkill X
|
|
fi
|
|
;;
|
|
"$option2")
|
|
if confirm_action " Are you sure you want to reboot?"; then
|
|
systemctl reboot
|
|
fi
|
|
;;
|
|
"$option3")
|
|
if confirm_action " Are you sure you want to power off?"; then
|
|
systemctl poweroff
|
|
fi
|
|
;;
|
|
"$option4")
|
|
systemctl suspend
|
|
;;
|
|
"$option5")
|
|
slock -b "$currentwall"
|
|
;;
|
|
"$option6")
|
|
# Determine current power profile for submenu
|
|
case "$currentpwr" in
|
|
"performance")
|
|
currentpwr="$pwr1"
|
|
;;
|
|
"balanced")
|
|
currentpwr="$pwr2"
|
|
;;
|
|
"power-saver")
|
|
currentpwr="$pwr3"
|
|
;;
|
|
*)
|
|
currentpwr="Unknown"
|
|
;;
|
|
esac
|
|
|
|
# Show power profile submenu and get user action
|
|
pwraction=$(echo -e "$pwrs" | dmenu -i -p " Power Profile Menu - Currently set to: $currentpwr")
|
|
case "$pwraction" in
|
|
"$pwr1")
|
|
if [ "$currentpwr" = "$pwr1" ]; then
|
|
notify-send "The power profile is already set to performance"
|
|
else
|
|
powerprofilesctl set performance && notify-send "Power profile switched to performance"
|
|
fi
|
|
;;
|
|
"$pwr2")
|
|
if [ "$currentpwr" = "$pwr2" ]; then
|
|
notify-send "The power profile is already set to balanced"
|
|
else
|
|
powerprofilesctl set balanced && notify-send "Power profile switched to balanced"
|
|
fi
|
|
;;
|
|
"$pwr3")
|
|
if [ "$currentpwr" = "$pwr3" ]; then
|
|
notify-send "The power profile is already set to power saver"
|
|
else
|
|
powerprofilesctl set power-saver && notify-send "Power profile switched to power saver"
|
|
fi
|
|
;;
|
|
"$pwr4")
|
|
exit 0
|
|
;;
|
|
esac
|
|
;;
|
|
"$option7")
|
|
exit 0
|
|
;;
|
|
esac
|