Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- status() {
- # This is for the main battery, if there's none, just display nothing.
- bat0=$(sysctl -n hw.sensors.acpibat0)
- if [ "${bat0} != "" ]; then
- bat0full=$(sysctl -n hw.sensors.acpibat0.amphour0 | sed s/.A.*//)
- bat0warn=$(sysctl -n hw.sensors.acpibat0.amphour1 | sed s/.A.*//)
- bat0low=$(sysctl -n hw.sensors.acpibat0.amphour2 | sed s/.A.*//)
- bat0now=$(sysctl -n hw.sensors.acpibat0.amphour3 | sed s/.A.*//)
- # Get the battery capacity in percentage
- bat0cap=`echo "100 * ${bat0now} / ${bat0full}" | bc`
- bat0p="$bat0cap%"
- # Get the charging status of the battery, replace with symbols
- bat0s=$(sysctl -n hw.sensors.acpibat0.raw0 | sed 's/'0'.*//; s/'1'.*/-/; s/'2'.*/+/; s/'4'.*/!/')
- else
- bat0p=`echo ""`
- bat0s=`echo ""`
- fi
- # This is for extended battery, if it's installed, display the status. Else just display nothing.
- bat1=$(sysctl -n hw.sensors.acpibat1)
- if [ "${bat1} != "" ]; then
- bat1full=$(sysctl -n hw.sensors.acpibat1.amphour0 | sed s/.A.*//)
- bat1warn=$(sysctl -n hw.sensors.acpibat1.amphour1 | sed s/.A.*//)
- bat1low=$(sysctl -n hw.sensors.acpibat1.amphour2 | sed s/.A.*//)
- bat1now=$(sysctl -n hw.sensors.acpibat1.amphour3 | sed s/.A.*//)
- # Get the battery capacity in percentage
- bat1cap=`echo "100 * ${bat1now} / ${bat1full}" | bc`
- bat1p="$bat1cap%"
- # Get the charging status of the battery, replace with symbols
- bat1s=$(sysctl -n hw.sensors.acpibat1.raw0 | sed 's/'0'.*//; s/'1'.*/-/; s/'2'.*/+/; s/'4'.*/!/')
- else
- bat1p=`echo ""`
- bat1s=`echo ""`
- fi
- # Get the AC Adapter status
- ac0=$(sysctl -n hw.sensors.acpiac0.indicator0 | sed s/.'('.*//)
- # Get the free memory data using top
- memfree=$(top | grep Memory | sed 's/.*Free:.//; s/.Swap.*//')
- # Get the CPU usage via top
- cpuuse=$(top | grep 'CPU states:' | grep 's/.*nice..//; s/.sys.*//')
- # Display the status bar
- echo CPU: $cpuuse '|' Mem: $memfree '|' Bat: ${bat0p}${bat0s} ${bat1p}${bat1s} '|' AC: $ac0 '|' $(date)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement