Last active
December 17, 2017 10:05
-
-
Save colby/92f466b919bba1217f55 to your computer and use it in GitHub Desktop.
A bash script for getting the laptop battery percentage for tmux.
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
#!/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