#!/bin/sh Green='\033[0;32m' Color_off='\033[0m' Red='\033[0;31m' Yellow='\033[1;33m' batteries=$(ls /sys/class/power_supply/ | grep BAT) case "$1" in "-c") if [[ "$batteries" == "" ]]; then printf "$Yellow**$Red error:$Color_off no battery found\n" exit 1; fi for i in $batteries; do batfull=$(cat /sys/class/power_supply/$i/charge_full) batnow=$(cat /sys/class/power_supply/$i/charge_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 "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 ;; "-j") if [[ "$batteries" == "" ]]; then echo no exit 1; fi for i in $batteries; do batfull=$(cat /sys/class/power_supply/$i/charge_full) batnow=$(cat /sys/class/power_supply/$i/charge_now) batperc=$((($batnow/($batfull/100)))) printf "$batperc \n" done ;; esac