batt.sh (1191B)
1 2 #!/usr/bin/env sh 3 4 colors() { 5 [ "$1" -lt "15" ] && printf "$COL_VERMELL" && exit 6 [ "$1" -lt "35" ] && printf "$COL_TARONJA" && exit 7 [ "$1" -lt "60" ] && printf "$COL_GROC" && exit 8 printf "$COL_BLANC" 9 } 10 11 icona() { 12 [ "$1" -lt "15" ] && printf "" && exit 13 [ "$1" -lt "35" ] && printf "" && exit 14 [ "$1" -lt "60" ] && printf "" && exit 15 [ "$1" -lt "80" ] && printf "" && exit 16 printf "" 17 } 18 19 IC_CURRENT="^c$COL_GROC^" 20 IC_PLUG="^c$COL_BLANC^" 21 22 acpi > /tmp/acpi_info 23 while read line; do 24 percent="$(echo "$line" | awk -F ', ' '{print $2}' | sed 's/.$//')" 25 26 if echo "$line" | grep "Discharging," > /dev/null; then 27 # DESCARREGANT 28 printf "^c$(colors "$percent")^" 29 printf "$(icona "$percent") " 30 printf "$percent%%" 31 32 time_left="$(echo "$line" | awk '{print $5}' | sed "s/:[0-9][0-9]$//g")" 33 printf " ($time_left)" 34 35 elif echo "$line" | grep "Full" > /dev/null; then 36 # COMPLETAMENT CARREGADA 37 printf "$IC_PLUG 100%%" 38 39 elif ! echo "$line" | grep "Unknown" > /dev/null; then 40 # CARREGANT 41 printf "$IC_CURRENT $IC_PLUG $percent%%" 42 43 fi 44 done < /tmp/acpi_info