Share a single power profile parser between list and set

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-07-19 21:29:15 -07:00
co-authored by Claude Fable 5
parent d211de2ffc
commit f3878b341c
2 changed files with 8 additions and 10 deletions
+7 -9
View File
@@ -8,12 +8,10 @@ if [[ ${1:-} != "" && ${1:-} != "--active-state" ]]; then
exit 1
fi
if [[ ${1:-} == "--active-state" ]]; then
powerprofilesctl list 2>/dev/null |
awk '/^\s*[* ]\s*[a-zA-Z0-9-]+:$/ { active=($1=="*"); gsub(/^[*[:space:]]+|:$/,""); print $0 "\t" (active ? 1 : 0) }' |
tac
else
powerprofilesctl list 2>/dev/null |
awk '/^\s*[* ]\s*[a-zA-Z0-9-]+:$/ { gsub(/^[*[:space:]]+|:$/,""); print }' |
tac
fi
powerprofilesctl list 2>/dev/null |
awk -v with_state="${1:+1}" '/^\s*[* ]\s*[a-zA-Z0-9-]+:$/ {
active = ($1 == "*") ? 1 : 0
gsub(/^[*[:space:]]+|:$/, "")
print $0 (with_state ? "\t" active : "")
}' |
tac
+1 -1
View File
@@ -27,7 +27,7 @@ case "$action" in
*) usage ;;
esac
mapfile -t profiles < <(powerprofilesctl list | awk '/^\s*[* ]\s*[a-zA-Z0-9\-]+:$/ { gsub(/^[*[:space:]]+|:$/,""); print }')
mapfile -t profiles < <(omarchy-powerprofiles-list)
profile_available() {
[[ " ${profiles[*]} " == *" $1 "* ]]