cbat-crystal executable
CBAT-Crystal
A simple Crystal program to display current battery information, made with the idea of having little to no dependencies and being easy to understand and modify. The battery name will be displayed alongside a simple ascii bar, charge percentage and current state, like so:
<BAT0> [████░░░░░░░░░░░░░░░░] [21%] [Discharging]
BAT0|▮▮▯▯▯▯▯▯▯▯▯▯▯▯▯|10%|Discharging
How to build cbat yourself
You can compile the cbat
either through shards
or with the compile
script included in the project. Shards is the Crystal way of building while compile
is a simple shell script to build cbat
as minimal as posible.
- Clone this repository and check the source code in the 'src' and 'src/res' directories.
- Modify to your liking and save it.
- Make sure you have crystal installed in your system by running:
crystal --version
- To build it, run the following command: Building using
shardas
:shards build
Building withcompile
:sh compile
- Go to the 'bin' directory created inside the project and run
./cbat
.
Note: Remember to give execution permissions to cbat: chmod +x cbat
.
Dependencies
At the current version, none.
Where is the data gathered from?
All the information is gathered from the /sys/class/power_supply/BAT*/capacity
and /sys/class/power_supply/BAT*/status
files. If your system saves the battery information in another directory, you might want to change the class attribute @supply_dir
to the right directory for your system.
How to run your cbat file
- You can make a soft link to the cbat executable. Run in the terminal:
ln -s /absolute/path/to/cbat/ /usr/local/bin
- Place an alias in your
~/.bashrc
file. Just add the line:alias cbat='/path/to/cbat/'
then, save and quit. - Source it:
source ~/.bashrc
- Try running:
cbat
cbat-crystal
- 2
- 0
- 0
- 0
- 0
- 18 days ago
- August 25, 2023
MIT License
Thu, 26 Dec 2024 20:41:59 GMT