Skip to content

Instantly share code, notes, and snippets.

@strazzere
Created August 4, 2014 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strazzere/e76cdc50084cdfb53df4 to your computer and use it in GitHub Desktop.
Save strazzere/e76cdc50084cdfb53df4 to your computer and use it in GitHub Desktop.
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