Skip to content

Instantly share code, notes, and snippets.

@haylinmoore
Created February 16, 2020 18:00
Show Gist options
  • Select an option

  • Save haylinmoore/e0260d9194d25fd92af268b07c1de439 to your computer and use it in GitHub Desktop.

Select an option

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