Advertisement
Guest User

Untitled

a guest
Jul 19th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.91 KB | None | 0 0
  1. status() {
  2.  # This is for the main battery, if there's none, just display nothing.
  3.  bat0=$(sysctl -n hw.sensors.acpibat0)
  4.  if [ "${bat0} != "" ]; then
  5.  bat0full=$(sysctl -n hw.sensors.acpibat0.amphour0 | sed s/.A.*//)
  6.  bat0warn=$(sysctl -n hw.sensors.acpibat0.amphour1 | sed s/.A.*//)
  7.  bat0low=$(sysctl -n hw.sensors.acpibat0.amphour2 | sed s/.A.*//)
  8.  bat0now=$(sysctl -n hw.sensors.acpibat0.amphour3 | sed s/.A.*//)
  9.  
  10.  # Get the battery capacity in percentage
  11.  bat0cap=`echo "100 * ${bat0now} / ${bat0full}" | bc`
  12.  bat0p="$bat0cap%"
  13.  
  14.  # Get the charging status of the battery, replace with symbols
  15.  bat0s=$(sysctl -n hw.sensors.acpibat0.raw0 | sed 's/'0'.*//; s/'1'.*/-/; s/'2'.*/+/; s/'4'.*/!/')
  16. else
  17.  bat0p=`echo ""`
  18.  bat0s=`echo ""`
  19. fi
  20.  
  21. # This is for extended battery, if it's installed, display the status. Else just display nothing.
  22. bat1=$(sysctl -n hw.sensors.acpibat1)
  23. if [ "${bat1} != "" ]; then
  24.   bat1full=$(sysctl -n hw.sensors.acpibat1.amphour0 | sed s/.A.*//)
  25.   bat1warn=$(sysctl -n hw.sensors.acpibat1.amphour1 | sed s/.A.*//)
  26.   bat1low=$(sysctl -n hw.sensors.acpibat1.amphour2 | sed s/.A.*//)
  27.   bat1now=$(sysctl -n hw.sensors.acpibat1.amphour3 | sed s/.A.*//)
  28.  
  29.   # Get the battery capacity in percentage
  30.   bat1cap=`echo "100 * ${bat1now} / ${bat1full}" | bc`
  31.   bat1p="$bat1cap%"
  32.  
  33.   # Get the charging status of the battery, replace with symbols
  34.   bat1s=$(sysctl -n hw.sensors.acpibat1.raw0 | sed 's/'0'.*//; s/'1'.*/-/; s/'2'.*/+/; s/'4'.*/!/')
  35.  else
  36.   bat1p=`echo ""`
  37.   bat1s=`echo ""`
  38.  fi
  39.  
  40.  # Get the AC Adapter status
  41.  ac0=$(sysctl -n hw.sensors.acpiac0.indicator0 | sed s/.'('.*//)
  42.  
  43.  # Get the free memory data using top
  44.  memfree=$(top | grep Memory | sed 's/.*Free:.//; s/.Swap.*//')
  45.  
  46.  # Get the CPU usage via top
  47.  cpuuse=$(top | grep 'CPU states:' | grep 's/.*nice..//; s/.sys.*//')
  48.  
  49.  # Display the status bar
  50.  echo CPU: $cpuuse '|' Mem: $memfree '|' Bat: ${bat0p}${bat0s} ${bat1p}${bat1s} '|' AC: $ac0 '|' $(date)
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement