Skip to content

Instantly share code, notes, and snippets.

@colby
Last active December 17, 2017 10:05
Show Gist options
  • Save colby/92f466b919bba1217f55 to your computer and use it in GitHub Desktop.
Save colby/92f466b919bba1217f55 to your computer and use it in GitHub Desktop.
A bash script for getting the laptop battery percentage for tmux.
#!/bin/bash
#
# To include the line below into your .tmux.conf to see battery % or charging icon.
# set -g status-right "#(/Users/colbyolson/src/scripts/battery.sh) #H %H:%M"
ok_color="colour236"
warn_percent="20"
warn_color="colour208"
status=$(pmset -g batt)
percent=$(echo $status | cut -d' ' -f7 | cut -d'%' -f1)
if [[ "$percent" -lt "$warn_percent" ]]; then
color="#[fg=$warn_color]"
else
color="#[fg=$ok_color]"
fi
if [[ $status == *Battery*Power* ]]; then
printf "%s%s%s" "$color" "$percent%" "#[default]"
else
printf "%s%s%s" "$color" "⚡" "#[default]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment