[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: setup apm for 'battery low' warning on textconsole



Alle feb 13 at 11:36, Jason Kraftcheck scrisse:

>Here's some junk from my .bashrc to color the shell prompt according to 
>the battery life:

I change your script for the ACPI :) It's great :)

if [ `cat /proc/acpi/battery/BAT0/state | grep present: |cut -d\  -f18` = "yes" ]; then

function acpi_percent()
{
 CAPACITY=`cat /proc/acpi/battery/BAT0/info |grep "design capacity:"|cut -d\  -f11`
 LEVEL=`cat /proc/acpi/battery/BAT0/state | grep remaining|cut -d\  -f8`
 ACPI_PERCENT=`echo $(( $LEVEL * 100 / $CAPACITY ))`
 if [ "$LEVEL" = "$CAPACITY" ]; then 
  echo full
 else
  echo $ACPI_PERCENT%
 fi
}

function acpi_charge()
{
 ACPI_CHARGE=`cat /proc/acpi/ac_adapter/AC/state | cut -d\  -f20`
 case $ACPI_CHARGE in
       *on-line*)
         ACPI_CHARGE="+" ;;
       *off-line*)
         ACPI_CHARGE="-" ;;
     esac
     echo $ACPI_CHARGE
}

function acpi_color()
   {
     if  [  "$(acpi_charge)"  =  "+"  ];  then
       echo  "1;32"
     else
       case  $(acpi_percent)  in
          10?%)  echo  "0;32"  ;;
           9?%)  echo  "0;32"  ;;
           8?%)  echo  "0;32"  ;;
           7?%)  echo  "0;32"  ;;
           6?%)  echo  "0;32"  ;;
           5?%)  echo  "0;32"  ;;
           4?%)  echo  "0;33"  ;;
           3?%)  echo  "0;33"  ;;
           2?%)  echo  "0;33"  ;;
           1?%)  echo  "0;31"  ;;
            ?%)  echo  "0;31;5"  ;;
             *)  echo  "0;35"  ;;
       esac
     fi
   }

function  acpi_color_prompt
   {
     PS1='\[\e[$(acpi_color)m\][$(acpi_charge)$(acpi_percent)][\t] \u:\w\$>\[\e[0;37m\] '
     #PS1="\[\e[$(acpi_color)m\]\h\$\[\e[0m\]  "
   }

   #  linux  console
   if  [  "$TERM"  =  "linux"  ];  then
     PROMPT_COMMAND=acpi_color_prompt
   fi

   function  echo_acpi
   {
     echo -n "($(acpi_charge)$(acpi_percent)) "
   }

   #  alternately echo apm state before prompt
   #  PROMPT_COMMAND = echo_apm

else PS1='\[\e[0;31m\][no battery][\t] \u:\w\$>\[\e[0;37m\] '

fi

-- 
Fabio
_____________________________________________________________________
Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France



Reply to: