neodotfiles/user/.local/bin/rs_power

113 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)***
2023-10-21 13:44:39 +00:00
# - Description: A simple power menu script for rofi/dmenu/wofi
# - Dependencies: {rofi||dmenu||wofi}, power-profiles-daemon, swaylock
#
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-21 13:44:39 +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-21 13:44:39 +00:00
#####
## This variable will store the current wallpaper
#####
2023-10-25 11:20:57 +00:00
currwall="$HOME/.config/sway/wallpaper/locked.*"
2023-10-21 13:44:39 +00:00
2023-10-03 14:40:20 +00:00
#####
## This variable will store the current power profile
#####
currentpwr=$(powerprofilesctl get)
2023-10-26 19:56:17 +00:00
if [ "$currentpwr" = "performance" ]; then
currentpwr="$pwr1"
elif [ "$currentpwr" = "balanced" ]; then
currentpwr="$pwr2"
elif [ "$currentpwr" = "power-saver" ]; then
currentpwr="$pwr3"
fi
# prompts
prompt1="[ Power Options]  "
prompt2="[ Power Profiles - Currently set to: $currentpwr]  "
2023-10-03 14:40:20 +00:00
2023-10-21 13:44:39 +00:00
#####
## This variable will store the currently active session in tty1
#####
ACTIVE_SESSION=$(loginctl list | grep -E "$USER.*tty1" | awk '{print $1}')
2023-09-04 17:36:18 +00:00
##########
## main ##
##########
2023-10-26 19:56:17 +00:00
action=$(echo -e "$options" | $RUNNER -l 7 -p "$prompt1") # main menu prompt
2022-12-20 00:15:21 +00:00
case "$action" in
2023-09-04 17:36:18 +00:00
"$option1")
2023-10-21 13:44:39 +00:00
loginctl kill-session "$ACTIVE_SESSION"
2023-09-04 17:36:18 +00:00
;;
"$option2")
2023-10-21 13:44:39 +00:00
loginctl reboot
2023-09-04 17:36:18 +00:00
;;
"$option3")
2023-10-21 13:44:39 +00:00
loginctl poweroff
2023-09-04 17:36:18 +00:00
;;
"$option4")
2023-10-21 13:44:39 +00:00
swaylock -i "$currwall" &
sleep 0.1
loginctl suspend
2023-09-04 17:36:18 +00:00
;;
"$option5")
2023-10-21 13:44:39 +00:00
swaylock -i "$currwall"
2023-09-04 17:36:18 +00:00
;;
"$option6")
2023-10-03 14:40:20 +00:00
#####
## These conditions will be used for the prompt
#####
2023-10-26 19:56:17 +00:00
pwraction=$(echo -e "$pwrs" | $RUNNER -l 3 -p "$prompt2")
2022-12-20 00:15:21 +00:00
case "$pwraction" in
2023-09-04 17:36:18 +00:00
"$pwr1")
2023-10-21 13:44:39 +00:00
if [ "$currentpwr" = "$pwr1" ]; then
notify-send "The power profile is already set to performance"
exit 1
2023-10-03 14:40:20 +00:00
else
2023-10-21 13:44:39 +00:00
powerprofilesctl set performance && notify-send "Power profile switched to performance"
2023-10-03 14:40:20 +00:00
fi
2023-09-04 17:36:18 +00:00
;;
"$pwr2")
2023-10-21 13:44:39 +00:00
if [ "$currentpwr" = "$pwr2" ]; then
notify-send "The power profile is already set to balanced"
exit 1
2023-10-03 14:40:20 +00:00
else
2023-10-21 13:44:39 +00:00
powerprofilesctl set balanced && notify-send "Power profile switched to balanced"
2023-10-03 14:40:20 +00:00
fi
2023-09-04 17:36:18 +00:00
;;
"$pwr3")
2023-10-21 13:44:39 +00:00
if [ "$currentpwr" = "$pwr3" ]; then
notify-send "The power profile is already set to power saver"
exit 1
2023-10-03 14:40:20 +00:00
else
2023-10-21 13:44:39 +00:00
powerprofilesctl set power-saver && notify-send "Power profile switched to power saver"
2023-10-03 14:40:20 +00:00
fi
2023-09-04 17:36:18 +00:00
;;
"$pwr4")
2023-10-21 13:44:39 +00:00
exit 0
2023-10-03 14:40:20 +00:00
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