Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/st3iny/batteryhook
Run commands on certain battery levels.
https://github.com/st3iny/batteryhook
Last synced: 8 days ago
JSON representation
Run commands on certain battery levels.
- Host: GitHub
- URL: https://github.com/st3iny/batteryhook
- Owner: st3iny
- License: mit
- Created: 2020-05-31T14:41:03.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-01T13:38:57.000Z (almost 4 years ago)
- Last Synced: 2023-04-05T06:35:52.576Z (over 1 year ago)
- Language: Go
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# batteryhook
Run commands on certain battery levels.
Written in go.## Usage
```
Usage: batteryhook [-h|--help] [-v] [-i INTERVAL] [-b BATTTERY]
-b string
Select battery to watch (default "BAT0")
-i uint
Battery refresh interval in ms (default 5000)
-t string
Test hooks in level interval (format "BEGIN[-END]")
-v Increase verbosityHooks are defined in the file $XDG_CONFIG_HOME/batteryhook/config.yaml.
This path defaults to ~/.config/batteryhook/config.yaml on most machines.Example config.yaml:
hooks:
- status:
discharging: true
level: 10
command: systemctl hibernateThis will hibernate your machine when it falls below 10% while discharging.
Valid statuses are: unknown, discharging, charging, not_charging and full
Status defaults to (if omitted): discharging
Refer to the linux documentation for more information on battery status (power_supply.h).
```## Build
Run `make build` to build batteryhook.## Install
Run `make install` to build and install batteryhook to `/usr/local/bin`.A custom target directory can be set via the `PREFIX` variable.
Run `make PREFIX=~/.local install` to install batteryhook to `~/.local/bin`.## Examples for `config.yaml`
Notify about low battery and hibernate on very low battery (requires [libnotify](https://gitlab.gnome.org/GNOME/libnotify)):
```yaml
hooks:
- status:
discharging: true
level: 25
command: notify-send "Battery is running low"
- status:
discharging: true
discharging: true
level: 10
command: systemctl hibernate
```Run multiple commands per hook using POSIX shell syntax (requires [libnotify](https://gitlab.gnome.org/GNOME/libnotify) and [brightnessctl](https://github.com/Hummer12007/brightnessctl)):
```yaml
hooks:
- status:
discharging: true
level: 20
command: notify-send "Low battery" && brightnessctl s 10%
```Omitting a status will cause it to default to discharging.