Commit 43dd9f49b97c797aa58ba8c6cadc9ec1867da590
1 parent
ae8c717f
Exists in
master
add makefile and update README
Showing
3 changed files
with
16 additions
and
52 deletions
Show diff stats
README.md
1 | -# Battery indicator for tmux/FreeBSD | 1 | +# Battery indicator for tmux |
2 | 2 | ||
3 | This is is a little C program to indicate the current battery state and | 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. | 4 | +percentage in the tmux status bar. It is tmux specific as it generates status |
5 | +configuration colors according to the battery level. | ||
6 | 6 | ||
7 | -Requires a font that includes utf-8 symbols. Iosevka and JetBrains Mono from | ||
8 | -NerdFonts have been tested. | 7 | +It supports Linux (using `/sys/class/power_supply`) and FreeBSD with `sysctl`. |
9 | 8 | ||
10 | -Compile with | 9 | +Requires a font that includes battery symbols. Iosevka and JetBrains Mono |
10 | +from NerdFonts have been tested. the output is generated in utf-8. | ||
11 | 11 | ||
12 | -```sh | ||
13 | -cc -O2 battery.c -o battery | ||
14 | -``` | ||
15 | - | ||
16 | -and copy or link the executable into `~/.local/bin`, which should be on your | ||
17 | -`$PATH`. | 12 | +Compile with gnu `make` (`gmake` command in FreeBSD) and copy or link the |
13 | +executable into `~/.local/bin`, which should be on your `$PATH`. | ||
18 | 14 | ||
19 | Edit `~/.tmux.conf` and setup the status bar with something like | 15 | Edit `~/.tmux.conf` and setup the status bar with something like |
20 | 16 | ||
21 | ```tmux | 17 | ```tmux |
22 | -set-option -g status-right "#($HOME/.local/bin/battery) %a, %d %b %H:%M " | 18 | +set-option -g status-right " #($HOME/.local/bin/battery) %a, %d %b %H:%M " |
23 | ``` | 19 | ``` |
24 | 20 | ||
25 | Reload tmux and enjoy! | 21 | Reload tmux and enjoy! |
battery.py
@@ -1,39 +0,0 @@ | @@ -1,39 +0,0 @@ | ||
1 | -#!/usr/bin/env python3 | ||
2 | - | ||
3 | -import subprocess | ||
4 | - | ||
5 | -bat_icons = [ | ||
6 | - "\uf58d", # 0% | ||
7 | - "\uf579", | ||
8 | - "\uf57a", | ||
9 | - "\uf57b", | ||
10 | - "\uf57c", | ||
11 | - "\uf57d", # 50% | ||
12 | - "\uf57e", | ||
13 | - "\uf57f", | ||
14 | - "\uf580", | ||
15 | - "\uf581", | ||
16 | - "\uf578", # 100% | ||
17 | -] | ||
18 | -# bat_alert = f582 | ||
19 | -# bat_plus = f58e | ||
20 | -# bat_minus = f58b | ||
21 | -# bat_unknown = f590 | ||
22 | -# bat_charging = f583 | ||
23 | - | ||
24 | -out = str( | ||
25 | - subprocess.run(["sysctl", "hw.acpi.battery"], capture_output=True).stdout, "UTF-8" | ||
26 | -) | ||
27 | -bat = dict(line.split(": ") for line in out.splitlines()) | ||
28 | - | ||
29 | -state = int(bat["hw.acpi.battery.state"]) | ||
30 | -life = int(bat["hw.acpi.battery.life"]) | ||
31 | - | ||
32 | -if state == 0: # fully charged | ||
33 | - print(f"\uf583 Full") | ||
34 | -elif state == 1: # discharging | ||
35 | - print(f"{bat_icons[life // 10]} {life}%") | ||
36 | -elif state == 2: # charging | ||
37 | - print(f"\uf583 {life}%") | ||
38 | -elif state == 7: # disconnected | ||
39 | - print("\uf590 Disconnected") |