diff options
Diffstat (limited to 'quickshell/scripts')
| -rw-r--r-- | quickshell/scripts/battery-info.py | 39 | ||||
| -rwxr-xr-x | quickshell/scripts/battery-info.sh | 17 |
2 files changed, 56 insertions, 0 deletions
diff --git a/quickshell/scripts/battery-info.py b/quickshell/scripts/battery-info.py new file mode 100644 index 0000000..c3958f7 --- /dev/null +++ b/quickshell/scripts/battery-info.py @@ -0,0 +1,39 @@ +# this script was used to generate the battery-info.sh via chatgpt + +import subprocess + +output = subprocess.run( + ["upower", "--enumerate"], + capture_output=True +).stdout.decode('utf-8') + +target = None + +for line in output.split("\n"): + if "BAT" not in line: + continue + target = line + break + +print(line) + +output = subprocess.run( + ["upower", "-i", line], + capture_output=True +).stdout.decode('utf-8') + +energy = None +voltage = None +capacity = None + +for line in output.split("\n"): + if energy is None and "energy:" in line: + energy = line.split(":")[1].strip() + if voltage is None and "voltage:" in line: + voltage = line.split(":")[1].strip() + if capacity is None and "capacity:" in line: + capacity = line.split(":")[1].strip() + +print("energy:", energy) +print("voltage:", voltage) +print("capacity:", capacity) diff --git a/quickshell/scripts/battery-info.sh b/quickshell/scripts/battery-info.sh new file mode 100755 index 0000000..414d168 --- /dev/null +++ b/quickshell/scripts/battery-info.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +target=$(upower --enumerate | awk '/BAT/ { print; exit }') + +upower -i "$target" | awk -F: ' +/energy:/ && !e { e=$2 } +/voltage:/ && !v { v=$2 } +/capacity:/ && !c { c=$2 } +END { + gsub(/^[ \t]+/, "", e) + gsub(/^[ \t]+/, "", v) + gsub(/^[ \t]+/, "", c) + + print "energy:", e + print "voltage:", v + print "capacity:", c +}' |
