Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created September 21, 2016 09: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 hhc0null/89d7a0dd7de50767b27dd35b295ce3c6 to your computer and use it in GitHub Desktop.
Save hhc0null/89d7a0dd7de50767b27dd35b295ce3c6 to your computer and use it in GitHub Desktop.
battery?
#!/bin/sh
CAPACITY_PATH="/sys/class/power_supply/BAT1/capacity"
capacity=$(cat ${CAPACITY_PATH})
ESC="\e"
BK=40
LBK=100
FW=30
LFW=90
BLK=0
RED=1
GRN=2
YLW=3
BLE=4
MAG=5
CYN=6
LGR=7
RGB=8
TAIL="m"
RST="${ESC}[0m"
case $((
0 <= ${capacity} && ${capacity} <= 9 ? 1 :
10 <= ${capacity} && ${capacity} <= 19 ? 2 :
20 <= ${capacity} && ${capacity} <= 39 ? 3 :
40 <= ${capacity} && ${capacity} <= 79 ? 4 :
80 <= ${capacity} && ${capacity} <= 100? 5 : 0)) in
0)
m="BAT: NaN %"
;;
1)
m="$m${ESC}[$((${BK}+${RED}))mBAT: ${capacity}%${RST}"
;;
2)
m="$m${ESC}[$((${BK}+${RGB}));5;208mBAT: ${capacity}%${RST}"
;;
3)
m="$m${ESC}[$((${BK}+${YLW}))mBAT: ${capacity}%${RST}"
;;
4)
m="$m${ESC}[$((${BK}+${GRN}))mBAT: ${capacity}%${RST}"
;;
5)
m="$m${ESC}[$((${BK}+${BLE}))mBAT: ${capacity}%${RST}"
;;
esac
echo -e $m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment