Created
July 8, 2021 01:18
-
-
Save smutch/9972b67c518083386083e615dc5a1be5 to your computer and use it in GitHub Desktop.
sh: battery status for tmux
This file contains hidden or 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
#!/usr/bin/env bash | |
bstat=( $(pmset -g batt | grep -Eo '[0-9]+%.*' | awk '{print($1,$2)}' | tr -d ";") ) | |
percentage=$(echo "${bstat[0]}" | tr -d "%") | |
case $(( | |
(percentage >= 0 && percentage < 25) ? 1 : | |
(percentage >= 25 && percentage < 50) ? 2 : | |
(percentage >= 50 && percentage < 75) ? 3 : | |
(percentage >= 75 && percentage <= 100) ? 4 : 0 | |
)) in | |
1) | |
color='red' | |
;; | |
2) | |
color='orange' | |
;; | |
3) | |
color='yellow' | |
;; | |
4) | |
color='green' | |
;; | |
0) | |
color='default' | |
;; | |
esac | |
case ${bstat[1]} in | |
charging) | |
indicator="" | |
;; | |
discharging) | |
indicator="" | |
;; | |
AC) | |
indicator="ﮣ" | |
;; | |
esac | |
echo "#[fg=${color}]${indicator} ${bstat[0]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment