From 43dd9f49b97c797aa58ba8c6cadc9ec1867da590 Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Mon, 5 Feb 2024 11:29:33 +0000 Subject: [PATCH] add makefile and update README --- Makefile | 7 +++++++ README.md | 22 +++++++++------------- battery.py | 39 --------------------------------------- 3 files changed, 16 insertions(+), 52 deletions(-) create mode 100644 Makefile delete mode 100755 battery.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9fdd640 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ + +all: + cc -O2 battery.c -o battery + +clean: + rm battery + diff --git a/README.md b/README.md index 8733a8b..76ac057 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,21 @@ -# Battery indicator for tmux/FreeBSD +# Battery indicator for tmux This is is a little C program to indicate the current battery state and -percentage in the tmux status bar. -It uses the FreeBSD `sysctl` and is not compatible with Linux. +percentage in the tmux status bar. It is tmux specific as it generates status +configuration colors according to the battery level. -Requires a font that includes utf-8 symbols. Iosevka and JetBrains Mono from -NerdFonts have been tested. +It supports Linux (using `/sys/class/power_supply`) and FreeBSD with `sysctl`. -Compile with +Requires a font that includes battery symbols. Iosevka and JetBrains Mono +from NerdFonts have been tested. the output is generated in utf-8. -```sh -cc -O2 battery.c -o battery -``` - -and copy or link the executable into `~/.local/bin`, which should be on your -`$PATH`. +Compile with gnu `make` (`gmake` command in FreeBSD) and copy or link the +executable into `~/.local/bin`, which should be on your `$PATH`. Edit `~/.tmux.conf` and setup the status bar with something like ```tmux -set-option -g status-right "#($HOME/.local/bin/battery) %a, %d %b %H:%M " +set-option -g status-right " #($HOME/.local/bin/battery) %a, %d %b %H:%M " ``` Reload tmux and enjoy! diff --git a/battery.py b/battery.py deleted file mode 100755 index c6628eb..0000000 --- a/battery.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess - -bat_icons = [ - "\uf58d", # 0% - "\uf579", - "\uf57a", - "\uf57b", - "\uf57c", - "\uf57d", # 50% - "\uf57e", - "\uf57f", - "\uf580", - "\uf581", - "\uf578", # 100% -] -# bat_alert = f582 -# bat_plus = f58e -# bat_minus = f58b -# bat_unknown = f590 -# bat_charging = f583 - -out = str( - subprocess.run(["sysctl", "hw.acpi.battery"], capture_output=True).stdout, "UTF-8" -) -bat = dict(line.split(": ") for line in out.splitlines()) - -state = int(bat["hw.acpi.battery.state"]) -life = int(bat["hw.acpi.battery.life"]) - -if state == 0: # fully charged - print(f"\uf583 Full") -elif state == 1: # discharging - print(f"{bat_icons[life // 10]} {life}%") -elif state == 2: # charging - print(f"\uf583 {life}%") -elif state == 7: # disconnected - print("\uf590 Disconnected") -- libgit2 0.21.2