| Crates.io | battery_hearts |
| lib.rs | battery_hearts |
| version | 0.1.3 |
| created_at | 2025-10-09 14:45:47.918288+00 |
| updated_at | 2025-10-09 14:45:47.918288+00 |
| description | A terminal battery indicator using hearts - supports both nerdfont symbols and emoji |
| homepage | https://github.com/djensenius/battery_hearts |
| repository | https://github.com/djensenius/battery_hearts |
| max_upload_size | |
| id | 1875740 |
| size | 103,524 |
A terminal battery indicator using hearts - supports both nerdfont symbols and emoji!
Download the latest binary for your platform from the releases page.
# Download and make executable
chmod +x battery_hearts-*
./battery_hearts-* --version
cargo install battery_hearts
git clone https://github.com/djensenius/battery_hearts.git
cd battery_hearts
cargo build --release
./target/release/battery_hearts
battery_hearts is designed to be easily integrated into other applications, scripts, and tools.
For programmatic use, enable JSON output with --json:
battery_hearts --json --emoji
Output format:
{
"percentage": 0.750,
"charging": false,
"hearts": "โค๏ธ โค๏ธ ๐งก",
"status": "discharging"
}
Error format:
{
"error": "Could not determine battery status",
"percentage": null,
"charging": null,
"hearts": null,
"status": "unknown"
}
Use --quiet to suppress all error messages for clean script integration:
# Script-friendly usage
if battery_hearts --quiet --json > /dev/null; then
echo "Battery status available"
else
echo "Battery unavailable"
fi
#!/bin/bash
# Get battery info in JSON format
BATTERY_JSON=$(battery_hearts --json --emoji)
if [ $? -eq 0 ]; then
# Parse JSON (requires jq)
PERCENTAGE=$(echo "$BATTERY_JSON" | jq -r '.percentage')
CHARGING=$(echo "$BATTERY_JSON" | jq -r '.charging')
HEARTS=$(echo "$BATTERY_JSON" | jq -r '.hearts')
echo "Battery: ${PERCENTAGE} (${HEARTS})"
else
echo "Battery status unavailable"
fi
import subprocess
import json
import sys
def get_battery_status():
try:
result = subprocess.run(
['battery_hearts', '--json', '--emoji'],
capture_output=True,
text=True,
check=True
)
return json.loads(result.stdout)
except (subprocess.CalledProcessError, json.JSONDecodeError):
return None
# Usage
battery = get_battery_status()
if battery and 'error' not in battery:
print(f"Battery: {battery['percentage']:.1%} ({battery['hearts']})")
print(f"Status: {battery['status']}")
else:
print("Battery status unavailable")
const { execSync } = require('child_process');
function getBatteryStatus() {
try {
const output = execSync('battery_hearts --json --emoji', {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore']
});
return JSON.parse(output);
} catch (error) {
return null;
}
}
// Usage
const battery = getBatteryStatus();
if (battery && !battery.error) {
console.log(`Battery: ${(battery.percentage * 100).toFixed(1)}% (${battery.hearts})`);
console.log(`Status: ${battery.status}`);
} else {
console.log('Battery status unavailable');
}
tmux:
# Add to .tmux.conf
set -g status-right '#(battery_hearts --emoji) %Y-%m-%d %H:%M'
Waybar (Wayland):
{
"custom/battery-hearts": {
"exec": "battery_hearts --emoji",
"interval": 30,
"format": "{}",
"tooltip": false
}
}
Polybar (X11):
[module/battery-hearts]
type = custom/script
exec = battery_hearts --emoji
interval = 30
--quiet mode to avoid stderr pollution in scripts# Show battery with nerdfont hearts (default)
battery_hearts
# Show battery with emoji hearts
battery_hearts --emoji
Nerdfont mode (requires nerdfont compatible terminal):
๓ฐ ๓ฐ ๓ฑฑ # ~67% charging
๓ฐ ๓ฐ ๓ฑฒ # ~50% discharging
Emoji mode (works in any terminal):
โค๏ธ โค๏ธ โก # ~67% charging
โค๏ธ ๐งก ๐ # ~50% discharging
# Customize number of hearts
battery_hearts --max-hearts 5 --emoji
# Show percentage when battery is low
battery_hearts --threshold 0.25 --emoji
# Run visual test showing all battery levels
battery_hearts --test --emoji
# Use custom battery command
battery_hearts --cmd "your_custom_battery_command"
# Show help
battery_hearts --help
๓ฐ Full heart๓ฐ Half heart๓ฐ Empty heart๓ฑฑ Empty charging๓ฑฒ Empty discharging๓ฑฎ Full charging๓ฑฏ Full dischargingSet BATTERY_CMD to override the default battery detection command:
export BATTERY_CMD="your_custom_command"
battery_hearts
pmset (built-in)acpi or upower (may need installation)cargo build
# Run unit tests
cargo test
# Run visual tests
cargo run -- --test --emoji
# Lint and format
cargo clippy --all-targets --all-features
cargo fmt --all
This project uses GitHub Actions for:
cargo test && cargo clippy && cargo fmtMIT License - see LICENSE file for details.
Inspired by the need for a simple, cross-platform battery indicator that works well in terminal status bars and tmux configurations.