Commit 5c3ac22089596e6efb817ff45062aff1fcf2e371
1 parent
46dfb6a1
Exists in
master
Small update
Rewrite README.md Add directive to abort compilation on non FreeBSD systems.
Showing
2 changed files
with
19 additions
and
6 deletions
Show diff stats
README.md
1 | -# Battery for tmux in FreeBSD | 1 | +# Battery indicator for tmux/FreeBSD |
2 | 2 | ||
3 | -This is is a little program to use in the tmux status bar to indicate the | ||
4 | -current battery state a life. | 3 | +This is is a little C program to indicate the current battery state and |
4 | +percentage in the tmux status bar. | ||
5 | It uses the FreeBSD `sysctl` and is not compatible with Linux. | 5 | It uses the FreeBSD `sysctl` and is not compatible with Linux. |
6 | 6 | ||
7 | +Requires a font that includes utf-8 symbols. Iosevka and JetBrains Mono from | ||
8 | +NerdFonts have been tested. | ||
9 | + | ||
7 | Compile with | 10 | Compile with |
8 | 11 | ||
9 | ```sh | 12 | ```sh |
10 | cc -Os battery.c -o battery | 13 | cc -Os battery.c -o battery |
11 | ``` | 14 | ``` |
12 | 15 | ||
13 | -In `~/.tmux.conf` setup the status bar like the following, with the correct path | ||
14 | -to the executable. | 16 | +and copy the executable to `~/.local/bin`. |
17 | + | ||
18 | +In `~/.tmux.conf` setup the status bar with something like | ||
15 | 19 | ||
16 | ```tmux | 20 | ```tmux |
17 | -set-option -g status-right "#(/path/to/battery)" | 21 | +set-option -g status-right "#($HOME/.local/bin/battery) %a, %d %b %H:%M " |
18 | ``` | 22 | ``` |
battery.c
1 | +#ifndef __FreeBSD__ | ||
2 | + #error Only works on FreeBSD | ||
3 | +#endif | ||
4 | + | ||
1 | #include <stdio.h> | 5 | #include <stdio.h> |
2 | #include <stdlib.h> | 6 | #include <stdlib.h> |
3 | #include <sys/types.h> | 7 | #include <sys/types.h> |
@@ -27,6 +31,11 @@ int main() { | @@ -27,6 +31,11 @@ int main() { | ||
27 | exit(EXIT_FAILURE); | 31 | exit(EXIT_FAILURE); |
28 | } | 32 | } |
29 | 33 | ||
34 | + if (life > 100) | ||
35 | + life = 100; | ||
36 | + else if (life < 0) | ||
37 | + life = 0; | ||
38 | + | ||
30 | switch (state) { | 39 | switch (state) { |
31 | case 0: /* fully charged */ | 40 | case 0: /* fully charged */ |
32 | printf("\uf583 Full"); | 41 | printf("\uf583 Full"); |