| Crates.io | asusbat |
| lib.rs | asusbat |
| version | 0.4.2 |
| created_at | 2024-12-03 10:21:57.177528+00 |
| updated_at | 2024-12-10 14:20:56.581901+00 |
| description | Set battery charge limit on supported laptops on Linux with CLI |
| homepage | |
| repository | https://github.com/pepa65/asusbat |
| max_upload_size | |
| id | 1469845 |
| size | 62,722 |
Set battery charge limit on supported laptops on Linux with CLI
It is now widely acknowledged that the life span of Li-ion batteries is extended by not charging them to the max. An often recommended battery charge limit is 80.
5.4-rc1 or later (exposing the charge limit variable)systemd version 244 or later (supporting the directives in the included systemd service)/sys/class/power_supply/BAT?/*/etc/systemd/system/asusbat-TARGET.servicehibernate, hybrid-sleep, multi-user, sleep, suspend, suspend-then-hibernateasus-wmi: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/asus-wmi.cthinkpad_acpi: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/thinkpad_acpi.cdell-laptop: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/dell/dell-laptop.clg-laptop: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/lg-laptop.chuawei-wmi: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/huawei-wmi.csystem76_acpi: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/system76_acpi.cfujitsu-laptop: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/fujitsu-laptop.cmsi-ec: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/msi-ec.ctoshiba_acpi: https://github.com/torvalds/linux/blob/master/drivers/platform/x86/toshiba_acpi.cinfo works with any machine):
ASUS, Lenovo (ThinkPad), Dell, LG, Huawei, System76, Fujitsu, MSI en Toshiba.info: Show battery info (default).limit: Set battery charge limit (needs root privileges), takes percentage as argument.persist: Persist the charge limit through creating and enabling systemd services,
optionally takes percentage as argument for limit (needs root privileges).unpersist: Unpersist the charge limit by disabling and removing systemd services (needs root privileges).completions: Generate shell completions (bash, elvish, fish, powershell, zsh).asusbat u (unpersisting the limit).wget https://github.com/pepa65/asusbat/releases/download/0.4.2/asusbat
sudo mv asusbat /usr/local/bin/
sudo chown root:root /usr/local/bin/asusbat
sudo chmod +x /usr/local/bin/asusbat
If not installed yet, install a Rust toolchain, see https://www.rust-lang.org/tools/install
cargo install asusbat --target=x86_64-unknown-linux-musl
cargo install --git https://github.com/pepa65/asusbat --target=x86_64-unknown-linux-musl
git clone https://github.com/pepa65/asusbat
cd asusbat
rustup target add x86_64-unknown-linux-musl
export RUSTFLAGS='-C target-feature=+crt-static'
cargo build --release --target=x86_64-unknown-linux-musl
For smaller binary size: upx --best --lzma target/x86_64-unknown-linux-musl/release/asusbat
Even without a full Rust toolchain, rust binaries can be installed with the static binary cargo-binstall:
# Install cargo-binstall for Linux x86_64
# (Other versions are available at https://crates.io/crates/cargo-binstall)
wget github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz
tar xf cargo-binstall-x86_64-unknown-linux-musl.tgz
sudo chown root:root cargo-binstall
sudo mv cargo-binstall /usr/local/bin/
Install the musl binary: cargo-binstall asusbat
(Then asusbat will be installed in ~/.cargo/bin/ which will need to be added to PATH!)
asusbat 0.4.2 - Set battery charge limit on supported laptops on Linux with CLI
Usage: asusbat [COMMAND]
Commands:
info Print battery info (default command)
limit Set battery charge limit: PERCENT (1..100)
persist Persist charge limit with systemd: [PERCENT (1..100)]
unpersist Unpersist charge limit: disable and remove systemd services
completions Generate completions: SHELL (bash|elvish|fish|powershell|zsh)
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Root privileges required for: limit, persist & unpersist