Skip to content

Instantly share code, notes, and snippets.

@haylinmoore
Created February 16, 2020 18:00
Show Gist options
  • Save haylinmoore/e0260d9194d25fd92af268b07c1de439 to your computer and use it in GitHub Desktop.
Save haylinmoore/e0260d9194d25fd92af268b07c1de439 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
AVERAGE=$(ls /sys/class/power_supply | grep "BAT" | xargs -I % cat /sys/class/power_supply/%/capacity | awk '{ total += $1; count++ } END { printf "%.0f", total/count }')
STATUSES=$(ls /sys/class/power_supply | grep "BAT" | xargs -I % cat /sys/class/power_supply/%/status | sed -e "s/,//;s/Discharging/🔋/;s/Not charging//;s/Charging/🔌/;s/Unknown//;s/Full//;s/ 0*/ /g;s/ :/ /g" | tr -d '\n')
echo "$AVERAGE% $STATUSES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment