A simple yet powerful UI overlay made for Wayland WMs built with Quickshell
wayland
qs
linux
ui
ux
1#!/usr/bin/env bash
2
3set -u
4
5cmd="${1:-}"
6
7have_ppctl() { command -v powerprofilesctl >/dev/null 2>&1; }
8have_asusctl() { command -v asusctl >/dev/null 2>&1; }
9
10ppd_to_asus_profile() {
11 case "${1:-}" in
12 power-saver) echo "Quiet" ;;
13 balanced) echo "Balanced" ;;
14 performance) echo "Performance" ;;
15 *) echo "" ;;
16 esac
17}
18
19asus_profile_available() {
20 local want="${1:-}"
21 [ -n "$want" ] || return 1
22 asusctl profile list 2>/dev/null | tr -d $'\r' | grep -Fx "$want" >/dev/null 2>&1
23}
24
25apply_asus_profile_best_effort() {
26 have_asusctl || return 0
27
28 local ppd="${1:-}"
29 local ap
30 ap="$(ppd_to_asus_profile "$ppd")"
31 [ -n "$ap" ] || return 0
32
33 if asus_profile_available "$ap"; then
34 asusctl profile set "$ap" >/dev/null 2>&1 || true
35 fi
36
37 return 0
38}
39
40status() {
41 if ! have_ppctl; then
42 echo "NOPPD|1"
43 exit 0
44 fi
45
46 local p
47 p="$(powerprofilesctl get 2>/dev/null | tr -d $'\r' | head -n1)"
48 if [ -z "${p:-}" ]; then
49 echo "NOPPD|1"
50 exit 0
51 fi
52
53 echo "PROFILE|$p"
54 exit 0
55}
56
57set_profile() {
58 local p="${1:-}"
59 [ -n "$p" ] || exit 0
60
61 if ! have_ppctl; then
62 echo "NOPPD|1"
63 exit 0
64 fi
65
66 powerprofilesctl set "$p" >/dev/null 2>&1 || true
67
68 apply_asus_profile_best_effort "$p"
69
70 exit 0
71}
72
73case "$cmd" in
74 status) status ;;
75 set) shift; set_profile "${1:-}" ;;
76 *)
77 echo "NOPPD|1"
78 exit 0
79 ;;
80esac