Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions bin/omarchy-powerprofiles-set
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
# omarchy:args=[autodetect|ac|battery]

action="${1-}"
config_dir="${OMARCHY_CONFIG_HOME:-}"

if [[ -z $config_dir ]]; then
# udev runs this through systemd outside the user session, so $HOME
# may be /root. Derive the user config path from the install path.
executable=$(readlink -f "$0")

if [[ $executable == */.local/share/omarchy/bin/omarchy-powerprofiles-set ]]; then
config_dir="${executable%/.local/share/omarchy/bin/omarchy-powerprofiles-set}/.config/omarchy"
else
config_dir="$HOME/.config/omarchy"
fi
fi

config_path="$config_dir/powerprofiles.conf"

# Auto-detect when called with no argument: treat any Mains or USB
# power-supply device reporting online=1 as "on AC". This handles
Expand All @@ -30,16 +45,32 @@ fi

mapfile -t profiles < <(powerprofilesctl list | awk '/^\s*[* ]\s*[a-zA-Z0-9\-]+:$/ { gsub(/^[*[:space:]]+|:$/,""); print }')

configured_profile() {
local profile

profile=$(awk -F= -v source="$1" '$1 == source { print $2; exit }' "$config_path" 2>/dev/null)
[[ -n $profile && " ${profiles[*]} " == *" $profile "* ]] && echo "$profile"
}

case "$action" in
ac)
# Prefer performance, fall back to balanced
if [[ " ${profiles[*]} " == *" performance "* ]]; then
profile=$(configured_profile ac)

if [[ -n $profile ]]; then
powerprofilesctl set "$profile"
elif [[ " ${profiles[*]} " == *" performance "* ]]; then
powerprofilesctl set performance
else
powerprofilesctl set balanced
fi
;;
battery)
powerprofilesctl set balanced
profile=$(configured_profile battery)

if [[ -n $profile ]]; then
powerprofilesctl set "$profile"
else
powerprofilesctl set balanced
fi
;;
esac
esac
4 changes: 4 additions & 0 deletions config/omarchy/powerprofiles.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Persistent power profile defaults used by omarchy-powerprofiles-set.
# Values must match profiles listed by powerprofilesctl.
ac=performance
battery=balanced
24 changes: 24 additions & 0 deletions migrations/1780735021.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -e

echo "Add configurable power profile defaults"

config_dir="${OMARCHY_CONFIG_HOME:-$HOME/.config/omarchy}"

mkdir -p "$config_dir"

if [ ! -f "$config_dir/powerprofiles.conf" ]; then
if [ -z "${OMARCHY_PATH:-}" ]; then
echo "OMARCHY_PATH is required to seed power profile defaults" >&2
exit 1
fi

template="$OMARCHY_PATH/config/omarchy/powerprofiles.conf"

if [ ! -f "$template" ]; then
echo "Missing power profile defaults: $template" >&2
exit 1
fi
Comment thread
crmne marked this conversation as resolved.

cp "$template" "$config_dir/powerprofiles.conf"
fi
Comment thread
crmne marked this conversation as resolved.
Comment thread
crmne marked this conversation as resolved.
Comment thread
crmne marked this conversation as resolved.