Commit 5d8b1bfa5366

Vincent Demeester <vincent@sbr.pm>
2026-07-30 09:31:18
feat: add power profile switcher to raffi
Added pw keyword to switch tuned/powerprofilesctl profiles interactively. Shows active profile and supports both Fedora CSB (tuned-adm) and standard Fedora.
1 parent b7006fa
Changed files (2)
dots
dots/config/raffi/scripts/power-profile-raffi
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+# Power profile switcher for raffi script filter.
+# Uses tuned-adm (Fedora CSB) or powerprofilesctl.
+set -euo pipefail
+
+query="${1:-}"
+
+items="[]"
+
+if command -v tuned-adm &>/dev/null; then
+    active=$(tuned-adm active 2>/dev/null | sed 's/.*: //')
+    while IFS= read -r profile; do
+        profile=$(echo "$profile" | sed 's/^- //' | awk '{print $1}')
+        [[ -z "$profile" ]] && continue
+
+        if [[ -n "$query" ]] && ! echo "$profile" | grep -qi "$query"; then
+            continue
+        fi
+
+        if [[ "$profile" == "$active" ]]; then
+            status="✓ active"
+        else
+            status=""
+        fi
+
+        items=$(jq --arg name "$profile" --arg status "$status" \
+            '. + [{"title": $name, "subtitle": $status, "arg": $name}]' <<< "$items")
+    done < <(tuned-adm list 2>/dev/null | grep '^- ')
+elif command -v powerprofilesctl &>/dev/null; then
+    active=$(powerprofilesctl get 2>/dev/null)
+    for profile in power-saver balanced performance; do
+        if [[ -n "$query" ]] && ! echo "$profile" | grep -qi "$query"; then
+            continue
+        fi
+
+        if [[ "$profile" == "$active" ]]; then
+            status="✓ active"
+        else
+            status=""
+        fi
+
+        items=$(jq --arg name "$profile" --arg status "$status" \
+            '. + [{"title": $name, "subtitle": $status, "arg": $name}]' <<< "$items")
+    done
+fi
+
+jq -n --argjson items "$items" '{"items": $items}'
dots/config/raffi/raffi.yaml
@@ -101,6 +101,11 @@ addons:
     keyword: uid
     command: ~/.config/raffi/scripts/uid-raffi
     icon: clock
+  - name: Power Profile
+    keyword: pw
+    command: ~/.config/raffi/scripts/power-profile-raffi
+    icon: battery
+    action: tuned-adm profile {value} || powerprofilesctl set {value}
   - name: YubiKey OATH
     keyword: otp
     command: ~/.config/raffi/scripts/yubikey-oath-raffi