Created
August 4, 2014 19:36
-
-
Save strazzere/e76cdc50084cdfb53df4 to your computer and use it in GitHub Desktop.
battery colored output for osx shell
This file contains 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
# Should colorize output | |
alias battery="battery_stat" | |
function battery_stat() { | |
PERCENT=`ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%d", $10/$5 * 100)}'` | |
# Colors for humans | |
NON='\033[00m' | |
BLD='\033[01m' | |
RED='\033[01;31m' | |
GRN='\033[01;32m' | |
YEL='\033[01;33m' | |
COL="$RED" | |
if [ "$PERCENT" -gt "15" ] | |
then | |
COL="$YEL" | |
fi | |
if [ "$PERCENT" -gt "30" ] | |
then | |
COL="$GRN" | |
fi | |
echo -e "${COL}${PERCENT}%${NON}" | |
} | |
# Colors! | |
export PS1="[\$(battery)]\[\e[00;33m\]\u\[\e[0m\]\[\e[00;37m\]@\h:\[\e[0m\]\[\e[00;36m\][\W]\[\e[0m\] $ " | |
# output but colored: | |
# | |
# [99%]tstrazzere@bebop:[ldpreloadhook] $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment