Skip to content

Commit

Permalink
Update help and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
imwally committed Mar 29, 2024
1 parent 5889f5b commit 271e5bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
48 changes: 29 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,44 @@

`battstat` is a shell script that displays formatted information about the status of your battery.

Information is displayed in the order the format tokens are written. For example, the screenshots below show my __tmux__ status line running the command `battstat --percent-when-charged {i} {t} {p}`. This will display an icon, the time remaining when charging and discharging, and finally the percentage but only when the battery is fully charged. Format tokens can be written in any order and as many times as you like.

![battery charging](https://github.com/imwally/battstat/raw/master/img/charging.png)
![battery discharging](https://github.com/imwally/battstat/raw/master/img/discharging.png)
![battery full charged](https://github.com/imwally/battstat/raw/master/img/charged.png)
![battery discharging](/img/discharging.png)

## Examples

There are a few ways to customize the output of `battstat`. Charging and discharging icons can be replaced with single character or multi-character strings. The `-c` flag sets the charging string and the `-d` flag sets the discharging string.

```
$ battstat -d "🍕" {t} {i}
10:30 🍕
~ % battstat -d "💀"
11:25 74% 💀
~ % battstat -d "😎" -f "{i} ({t})"
😎 (11:15)
$ battstat {t} {i}
11:47 🔋
~ % battstat -c "AC:" -d "BAT:" -f "{i} {p} {t}"
BAT: 74% 11:35
$ battstat -c "AC:" -d "BAT:" {i} {p} {t}
BAT: 82% 12:11
~ % battstat -d "Battery:" -f "{i} {p}"
Battery: 74%
```

$ battstat {i} {p}
🔋 81%
## printf Formatting

$ battstat -d "Battery:" {i} {p}
Battery: 81%
`battstat` uses printf style formatting when using the `-f` flag. This means you can print replacement tokens however you want.

```
~ % battstat -f "{i}\t{t}\t({p})"
🔋 11:55 (74%)
~ % battstat -f "{i}\nType whatever you want.\n{t}\n({p})"
🔋
Type whatever you want.
12:05
(73%)
```

## macOS menu bar

![bitbar screenshot](https://github.com/imwally/battstat/blob/master/img/bitbar.png)
![bitbar screenshot](/img/bitbar.png)

Using [bitbar](https://github.com/matryer/bitbar) you can add the output of `battstat` to the menu bar on macOS. There are many ways to customize the output so I suggest reading over the [writing plugins](https://github.com/matryer/bitbar#writing-plugins) section to understand what's possible.

Expand All @@ -40,7 +48,7 @@ The screenshot above is using the following shell script. Make sure the script i
```
#!/bin/sh
time=$(/usr/local/bin/battstat {t})
time=$(/usr/local/bin/battstat -f {t})
echo "($time) | size=13"
```
Expand Down Expand Up @@ -79,12 +87,14 @@ options:
-h, --help display help information
-c, --charging-icon string to display in icon's place when battery is charging
-d, --discharging-icon string to display in icon's place when battery is discharging
-f, --format formatted output of battstat
--percent-when-charged only display percent when charged
format:
format replacement tokens:
{i} display icon
{t} display time remaining
{p} display percent
Note: There must be a space between each format token.
example:
battstat -f "Cool Battery: {t} ({p})"
```
6 changes: 4 additions & 2 deletions battstat
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ print_help() {
echo " -h, --help display help information"
echo " -c, --charging-icon string to display in icon's place when battery is charging"
echo " -d, --discharging-icon string to display in icon's place when battery is discharging"
echo " -f, --format formatted output of battstat"
echo " --percent-when-charged only display percent when charged"
echo ""
echo "format:"
echo "format replacement tokens:"
echo " {i} display icon"
echo " {t} display time remaining"
echo " {p} display percent"
echo ""
echo " Note: There must be a space between each format token."
echo "example:"
echo " battstat -f \"Cool Battery: {t} ({p})\""
}

exit_no_battery() {
Expand Down
Binary file modified img/discharging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 271e5bb

Please sign in to comment.