From 8cbadb61604667b407b53ee1258433994fa4765a Mon Sep 17 00:00:00 2001 From: coasteen Date: Thu, 9 Jul 2026 10:42:28 +0330 Subject: init --- local/bin/bat-symbol | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 local/bin/bat-symbol (limited to 'local/bin/bat-symbol') diff --git a/local/bin/bat-symbol b/local/bin/bat-symbol new file mode 100755 index 0000000..1ae28f8 --- /dev/null +++ b/local/bin/bat-symbol @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +def read_file(path): + try: + with open(path, "r") as f: + return f.read().strip() + except: + return None + +def get_battery_info(): + capacity = read_file("/sys/class/power_supply/BAT1/capacity") + status = read_file("/sys/class/power_supply/BAT1/status") + ac_online = read_file("/sys/class/power_supply/ACAD/online") + + try: + percent = int(capacity) + except (TypeError, ValueError): + percent = None + + charging = (status == "Charging") or (ac_online == "1") + return charging, percent + +def print_symbol(): + charging, percent = get_battery_info() + + if percent is None: + print("[?]") + return + + if charging and percent >= 90: + print("[++]") + elif charging and percent < 30: + print("[-+]") + elif charging: + print("[+]") + elif not charging and percent < 30: + print("[--]") + else: + print("[-]") + +if __name__ == "__main__": + print_symbol() -- cgit v1.2.3