Skip to content

Instantly share code, notes, and snippets.

@marsam
Created October 28, 2013 23:52
Show Gist options
  • Select an option

  • Save marsam/7206892 to your computer and use it in GitHub Desktop.

Select an option

Save marsam/7206892 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
hash acpi >/dev/null 2>&1 || return
HEART_FULL=█
HEART_HALF=▓
HEART_EMPTY=░
NUM_HEARTS=${NUM_HEARTS:-5}
cute_battery() {
local battery_perc=$(acpi | awk '{print $4}' | tr -d '%,')
local perc=$battery_perc
local inc=$(( 100 / $NUM_HEARTS))
local hearts=''
for ((i=1;i<=NUM_HEARTS;++i)); do
if [ $perc -lt 100 ]; then
hearts+=$HEART_EMPTY
else
hearts+=$HEART_FULL
fi
perc=$(( $perc + $inc ))
done
if [ $battery_perc -gt 10 ]; then
echo "#[fg=green]${battery_perc}% ${hearts}#[fg=colour254] "
else
echo "#[fg=red]${battery_perc}% ${hearts}#[fg=colour254] "
fi
}
cute_battery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment