Advertisement
Guest User

bateria.sh

a guest
Jan 12th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. Nota=$(upower -i $(upower -e | grep BAT) | grep percentage)
  4. Estado=$(cut -d' ' -f2 <<<$(upower -i $(upower -e|grep BAT)|grep state) )
  5. Percent=$(cut -d' ' -f2 <<<$Nota)
  6. Icone='/usr/share/icons/hicolor/48x48/status'
  7.  
  8. case $Percent in
  9.     100%) Faixa=100;cor=32
  10.     ;;
  11.     [0-9].*|1[0-9]*) Faixa=000;cor=31
  12.     ;;
  13.     [23][0-9]*) Faixa=020;cor=35
  14.     ;;
  15.     [45][0-9]*) Faixa=040;cor=33
  16.     ;;
  17.     [67][0-9]*) Faixa=060;cor=36
  18.     ;;
  19.     [89][0-9]*) Faixa=080;cor=32
  20.     ;;
  21. esac
  22.  
  23. case $Estado in
  24.     fully-charged)Estado=-charged
  25.     ;;
  26.     discharging)unset Estado
  27.     ;;
  28.     charging)Estado=-charging
  29.     ;;
  30. esac
  31.  
  32. # Confere se o estado é fully-charged com carga menor que 100%,
  33. # se for muda o ícone para xfpm-primary-missing.png
  34.  
  35. if [ "$Estado" = '-charged' -a "$Percent" != '100%' ]; then
  36.     unset Faixa
  37.     Estado=missing
  38. fi
  39.  
  40. if [ "$DISPLAY" ]; then
  41.   notify-send -i "$Icone"/xfpm-primary-$Faixa$Estado.png $Nota
  42. else
  43.     echo -e "\e[$cor;7m$(echo $Nota) $(\
  44.         [ -z "$Estado" ] && Estado=-discharging
  45.         [ "$Estado" = 'missing' ] && Estado='-charged @ '$Percent
  46.         echo $Estado)\e[m"
  47. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement