mi wrote:
Hello,while i was roaming on a textconsole, and the laptop only on battery, the machine suddenly powered off. Leaving it badly with filesystem checks.Now i wonder how to get a 'battery critical' warning yonder there .... ?
Here's some junk from my .bashrc to color the shell prompt according to the battery life:
APM="/usr/bin/apm" if [ -x $APM ]; then function apm_percent() { state_line=$($APM) cut_leading=${state_line#*: } APM_PERCENT=${cut_leading%%%*} echo $APM_PERCENT } function apm_charge() { case "$($APM)" in *on-line*) APM_CHARGE="+" ;; *off-line*) APM_CHARGE="-" ;; esac echo $APM_CHARGE } function apm_color() { if [ "$(apm_charge)" = "+" ]; then echo "1;37" else case $(apm_percent) in 10?) echo "1;37" ;; 9?) echo "0;34" ;; 8?) echo "0;34" ;; 7?) echo "0;34" ;; 6?) echo "0;34" ;; 5?) echo "0;32" ;; 4?) echo "0;32" ;; 3?) echo "1;33" ;; 2?) echo "1;33" ;; 1?) echo "0;31" ;; ?) echo "0;31;5" ;; *) echo "0;35" ;; esac fi } function apm_color_prompt { PS1="\[\e[$(apm_color)m\]\h\$\[\e[0m\] " } # linux console if [ "$TERM" = "linux" ]; then PROMPT_COMMAND=apm_color_prompt fi function echo_apm { echo -n "($(apm_charge)$(apm_percent)) " } # alternately echo apm state before prompt # PROMPT_COMMAND = echo_apm fi