Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
battery colored output for osx shell
# 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