Skip to content

Instantly share code, notes, and snippets.

@drakkhen
Created April 28, 2014 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drakkhen/11373776 to your computer and use it in GitHub Desktop.
Save drakkhen/11373776 to your computer and use it in GitHub Desktop.
battery_status
#!/bin/bash
plugged_in=`ioreg -c AppleSmartBattery | grep ExternalConnected | sed -e 's/^.* //'`
perc=`ioreg -c AppleSmartBattery | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f", $10/$5 * 100)}'`
perc_int=${perc/.*}
if [ $plugged_in == "Yes" ]; then
is_charging=`ioreg -c AppleSmartBattery | grep IsCharging | sed -e 's/^.* //'`
if [ $is_charging == "Yes" ]; then
status_color='#ff8000'
else
status_color='green,bright'
fi
else
status_color='black,bright'
fi
if [ $perc_int -le 5 ]; then
perc_color='red,reverse'
elif [ $perc_int -le 10 ]; then
perc_color='red'
elif [ $perc_int -le 30 ]; then
perc_color='yellow'
else
perc_color='green'
fi
if [ $perc_int -le 10 ]; then
warning=" #[fg=red]⚠"
fi
echo "#[fg=$status_color]• #[fg=$perc_color,nobright]$perc_int%#[noreverse]$warning"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment