Last active
September 25, 2018 22:10
-
-
Save lavoiesl/11023856 to your computer and use it in GitHub Desktop.
Apple Battery Status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # @link https://gist.github.com/lavoiesl/11023856 | |
| ioreg="$(ioreg -c AppleSmartBattery)" | |
| current="$(echo "$ioreg" | grep CurrentCapacity | grep -oE "[0-9]+" | head -n1)" | |
| max="$(echo "$ioreg" | grep MaxCapacity | grep -oE "[0-9]+" | head -n1)" | |
| battery="$(( current * 100 / max ))" | |
| echo -ne '|' | |
| if [[ -n "$1" ]]; then | |
| width="$1" | |
| if [[ "$width" -gt 0 ]]; then | |
| val=$(( battery * 2 * width / 100 )) | |
| for (( i = 1; i <= width; i++ )); do | |
| if [[ $val -ge $(( i * 2 )) ]]; then | |
| echo -n '+' | |
| elif [[ $val -ge $(( i * 2 - 1)) ]]; then | |
| echo -n '-' | |
| else | |
| echo -n ' ' | |
| fi | |
| done | |
| echo -n '|' | |
| fi | |
| fi | |
| # Pad with a space | |
| printf '%3d%%' $battery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment