Skip to content

Instantly share code, notes, and snippets.

@todd
Last active August 29, 2015 14:04
Show Gist options
  • Save todd/40cfd2ec74ae67aa7783 to your computer and use it in GitHub Desktop.
Save todd/40cfd2ec74ae67aa7783 to your computer and use it in GitHub Desktop.
Variable Color Battery Indicator for Tmux Status Bar on OS X
#!/bin/sh
input=$(pmset -g batt)
battery_level=$(echo $input | pcregrep -o1 -i "(\d+)%" | bc)
charging=$(echo $input | grep "AC")
color=yellow
bolt=""
if [ "$battery_level" -gt 75 ]; then
color=green
elif [ "$battery_level" -le 25 ]; then
color=red
fi
if [ -n "$charging" ]; then
bolt=" ⚡"
fi
echo "#[fg=${color}]${battery_level}%${bolt}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment