diff --git a/bin/batperc b/bin/batperc index 4a607e9..a14090f 100755 --- a/bin/batperc +++ b/bin/batperc @@ -12,21 +12,34 @@ if [[ "$batteries" == "" ]]; then exit 1; fi -for i in $batteries; do - batfull=$(cat /sys/class/power_supply/$i/energy_full) - batnow=$(cat /sys/class/power_supply/$i/energy_now) - batperc=$((($batnow/($batfull/100)))) +case "$1" in + "-c") + for i in $batteries; do + batfull=$(cat /sys/class/power_supply/$i/energy_full) + batnow=$(cat /sys/class/power_supply/$i/energy_now) + batperc=$((($batnow/($batfull/100)))) - if [[ "$batperc" -le "20" ]]; then - printf "$Yellow**$Color_off $i: $Red$batperc$Color_off\n" - exit 0 - fi + if [[ "$batperc" -le "20" ]]; then + printf "$Yellow**$Color_off $i: $Red$batperc$Color_off\n" + exit 0 + fi - if [[ "$batperc" -le "70" ]]; then - printf "$Yellow**$Color_off $i: $Yellow$batperc$Color_off\n" - exit 0 - fi + if [[ "$batperc" -le "70" ]]; then + printf "$Yellow**$Color_off $i: $Yellow$batperc$Color_off\n" + exit 0 + fi - printf "$Yellow**$Color_off $i: $Green$batperc$Color_off\n" -done + printf "$Yellow**$Color_off $i: $Green$batperc$Color_off\n" + done + ;; + "-j") + for i in $batteries; do + batfull=$(cat /sys/class/power_supply/$i/energy_full) + batnow=$(cat /sys/class/power_supply/$i/energy_now) + batperc=$((($batnow/($batfull/100)))) + + printf "$batperc \n" + done + ;; +esac diff --git a/bin/batpercd b/bin/batpercd new file mode 100755 index 0000000..fadc023 --- /dev/null +++ b/bin/batpercd @@ -0,0 +1,15 @@ +#!/bin/sh + +batperc=$(~/dotfiles/bin/batperc -j) + +echo $batperc + +while true; do + for i in $batperc; do + if [[ "$i" -le "20" ]]; then + notify-send "battery low: $i%" -u critical + sleep 60 + fi + done +done +