pipebattery.sh 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ######################################
  2. ## Battery Pipe Menu ##
  3. ## v 1.0 ##
  4. ## v 1.1 ##
  5. ## by jpope 01.18.2010 ##
  6. ## ##
  7. ## tested on Asus EeePC 1000HE(B) ##
  8. ## ##
  9. ######################################
  10. ## Settings
  11. batt=$(echo BAT0)
  12. ## Data
  13. batt_OEM=$(cat /proc/acpi/battery/"$batt"/info | grep 'OEM' | cut -c 26-)
  14. batt_Model=$(cat /proc/acpi/battery/"$batt"/info | grep 'model' | cut -c 26-)
  15. batt_type=$(cat /proc/acpi/battery/"$batt"/info | grep 'type' | cut -c 26-)
  16. batt_desncap=$(cat /proc/acpi/battery/"$batt"/info | grep 'design capacity:')
  17. batt_lastfull=$(cat /proc/acpi/battery/"$batt"/info | grep 'last')
  18. batt_desnvolt=$(cat /proc/acpi/battery/"$batt"/info | grep 'design v')
  19. batt_warn=$(cat /proc/acpi/battery/"$batt"/info | grep 'design capacity w')
  20. batt_low=$(cat /proc/acpi/battery/"$batt"/info | grep 'design capacity l')
  21. batt_state1=$(cat /proc/acpi/battery/"$batt"/state | grep 'capacity state' | cut -c 26-)
  22. batt_state2=$(cat /proc/acpi/battery/"$batt"/state | grep 'ch' | cut -c 26-)
  23. batt_rate=$(cat /proc/acpi/battery/"$batt"/state | grep 'present r')
  24. batt_volt=$(cat /proc/acpi/battery/"$batt"/state | grep 'present v')
  25. batt_cap=$(cat /proc/acpi/battery/"$batt"/state | grep 'remain')
  26. batt_r=$(cat /proc/acpi/battery/"$batt"/state | grep 'remain' | cut -c 26-29)
  27. batt_f=$(cat /proc/acpi/battery/"$batt"/info | grep 'last' | cut -c 26-29)
  28. batt_l=$(cat /proc/acpi/battery/"$batt"/info | grep 'design capacity l' | cut -c 26-29)
  29. batt_ra=$(cat /proc/acpi/battery/"$batt"/state | grep 'present r' | cut -c 26-29)
  30. batt_perc=$(echo "scale=4; ($batt_r/$batt_f)*100" | bc | cut -c -5)
  31. batt_time_c=$(echo "scale=4; ($batt_f-$batt_r)/$batt_ra" | bc | cut -c -4)
  32. batt_time_d=$(echo "scale=4; ($batt_r-$batt_l)/$batt_ra" | bc | cut -c -4)
  33. batt_time=$(case $(echo $batt_state2 | cut -c -7) in
  34. dischar) echo "approx time left: $batt_time_d hours" ;;
  35. chargin) echo "approx time to full: $batt_time_c hours" ;;
  36. charged) echo "full charge / on ac" ;;
  37. *) echo "battery time N/A"
  38. esac)
  39. ## Pipemenu
  40. echo "<openbox_pipe_menu>"
  41. echo "<separator label=\"$batt_OEM $batt_Model $batt_type $batt Info\"/>"
  42. echo "<item label=\"state: $batt_perc% $batt_state1 $batt_state2 \"/>"
  43. echo "<separator/>"
  44. echo "<item label=\"$batt_time\"/>"
  45. echo "<item label=\"$batt_rate\"/>"
  46. echo "<item label=\"$batt_cap\"/>"
  47. echo "<separator/>"
  48. echo "<item label=\"$batt_lastfull\"/>"
  49. echo "<item label=\"$batt_desncap\"/>"
  50. echo "<item label=\"$batt_warn\"/>"
  51. echo "<item label=\"$batt_low\"/>"
  52. echo "<separator/>"
  53. echo "<item label=\"$batt_volt\"/>"
  54. echo "<item label=\"$batt_desnvolt\"/>"
  55. echo "<separator/>"
  56. echo "<item label=\"Open Power Settings -->\">"
  57. echo "<action name=\"Execute\">"
  58. echo "<execute>"
  59. echo "gnome-power-preferences"
  60. echo "</execute>"
  61. echo "</action>"
  62. echo "</item>"
  63. echo "<item label=\"Open Power History -->\">"
  64. echo "<action name=\"Execute\">"
  65. echo "<execute>"
  66. echo "gnome-power-statistics"
  67. echo "</execute>"
  68. echo "</action>"
  69. echo "</item>"
  70. echo "</openbox_pipe_menu>"