mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-06-29 04:00:42 +00:00
Major rewrite: switching back to Arch from NixOS
This commit is contained in:
parent
df585b737b
commit
254181c0fc
121 changed files with 5433 additions and 2371 deletions
56
root/usr/local/bin/power-profiles-monitor
Executable file
56
root/usr/local/bin/power-profiles-monitor
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "You must run this script as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BAT=$(echo /sys/class/power_supply/BAT*) # only supports single-battery systems
|
||||
BAT_STATUS="$BAT/status"
|
||||
BAT_CAP="$BAT/capacity"
|
||||
OVERRIDE_FLAG="/tmp/power-monitor-override"
|
||||
|
||||
POWER_SAVE_PERCENT=50 # Enter power-save mode if on bat and below this capacity
|
||||
|
||||
HAS_PERFORMANCE="$(powerprofilesctl list | grep "performance" || true)" # the || true ignores grep failing with non-zero code
|
||||
|
||||
# monitor loop
|
||||
prev=0
|
||||
while true; do
|
||||
# check if override is set
|
||||
if [ -f "$OVERRIDE_FLAG" ]; then
|
||||
echo "Override flag set, waiting for release"
|
||||
inotifywait -qq "$OVERRIDE_FLAG"
|
||||
continue
|
||||
fi
|
||||
|
||||
# read the current state
|
||||
status="$(cat "$BAT_STATUS")"
|
||||
capacity="$(cat "$BAT_CAP")"
|
||||
|
||||
if [[ $status == "Discharging" ]]; then
|
||||
if [[ $capacity -le $POWER_SAVE_PERCENT ]]; then
|
||||
profile="power-saver"
|
||||
else
|
||||
profile="balanced"
|
||||
fi
|
||||
else
|
||||
if [[ -n $HAS_PERFORMANCE ]]; then
|
||||
profile="performance"
|
||||
else
|
||||
profile="balanced"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set the new profile
|
||||
if [[ "$profile" != "$prev" ]]; then
|
||||
echo -en "Setting power profile to ${profile}\n"
|
||||
powerprofilesctl set $profile
|
||||
prev=$profile
|
||||
fi
|
||||
|
||||
# wait for changes in status or capacity files
|
||||
# i.e. for the next power change event
|
||||
inotifywait -qq "$BAT_STATUS" "$BAT_CAP"
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue