Share a single power profile parser between list and set
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
d211de2ffc
commit
f3878b341c
@@ -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
|
||||
|
||||
@@ -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 "* ]]
|
||||
|
||||
Reference in New Issue
Block a user