Initial
This commit is contained in:
40
power-toggle.sh
Executable file
40
power-toggle.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get current profile safely
|
||||
current=$(powerprofilesctl get 2>/dev/null)
|
||||
|
||||
# get list of available profiles
|
||||
available=$(powerprofilesctl list 2>/dev/null)
|
||||
|
||||
# fallback if command failed
|
||||
if [ -z "$current" ]; then
|
||||
echo "powerprofilesctl not working"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# helper function
|
||||
has_profile(){
|
||||
echo "$available" | grep -q "$1"
|
||||
}
|
||||
|
||||
if [ "$current" = "performance" ]; then
|
||||
if has_profile "power-saver"; then
|
||||
powerprofilesctl set power-saver
|
||||
else
|
||||
powerprofilesctl set balanced
|
||||
fi
|
||||
|
||||
elif [ "$current" = "power-saver" ]; then
|
||||
powerprofilesctl set balanced
|
||||
|
||||
elif [ "$current" = "balanced" ]; then
|
||||
if has_profile "performance"; then
|
||||
powerprofilesctl set performance
|
||||
else
|
||||
powerprofilesctl set power-saver
|
||||
fi
|
||||
|
||||
else
|
||||
echo "Unknown profile: $current"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user