From 5c3ac22089596e6efb817ff45062aff1fcf2e371 Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Mon, 4 Jul 2022 18:04:06 +0100 Subject: [PATCH] Small update --- README.md | 16 ++++++++++------ battery.c | 9 +++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f0fe63d..3adffdf 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,22 @@ -# Battery for tmux in FreeBSD +# Battery indicator for tmux/FreeBSD -This is is a little program to use in the tmux status bar to indicate the -current battery state a life. +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. +Requires a font that includes utf-8 symbols. Iosevka and JetBrains Mono from +NerdFonts have been tested. + Compile with ```sh cc -Os battery.c -o battery ``` -In `~/.tmux.conf` setup the status bar like the following, with the correct path -to the executable. +and copy the executable to `~/.local/bin`. + +In `~/.tmux.conf` setup the status bar with something like ```tmux -set-option -g status-right "#(/path/to/battery)" +set-option -g status-right "#($HOME/.local/bin/battery) %a, %d %b %H:%M " ``` diff --git a/battery.c b/battery.c index 9f93b01..1a44745 100644 --- a/battery.c +++ b/battery.c @@ -1,3 +1,7 @@ +#ifndef __FreeBSD__ + #error Only works on FreeBSD +#endif + #include #include #include @@ -27,6 +31,11 @@ int main() { exit(EXIT_FAILURE); } + if (life > 100) + life = 100; + else if (life < 0) + life = 0; + switch (state) { case 0: /* fully charged */ printf("\uf583 Full"); -- libgit2 0.21.2