Last active
January 5, 2016 14:17
-
-
Save maio/0ad06423b2b96bb6f79a to your computer and use it in GitHub Desktop.
CPU usage chart for BitBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Real CPU Usage Chart | |
# BitBar plugin | |
# | |
# by Marian Schubert | |
# Based on work by Mat Ryer and Tyler Bunnell | |
# | |
# This script requires https://github.com/holman/spark | |
# | |
# Calcualtes and displays real CPU usage chart. | |
IDLE=`top -F -R -l3 | grep "CPU usage" | tail -1 | egrep -o '[0-9]{0,3}\.[0-9]{0,2}% idle' | sed 's/% idle//'` | |
CURRENT=`echo 100 - $IDLE | bc` | |
HISTORY_FILE="${HOME}/.cpu.history" | |
touch "${HISTORY_FILE}" | |
PREVIOUS=`tail -5 "${HISTORY_FILE}"` | |
echo "$PREVIOUS" > "${HISTORY_FILE}" | |
echo $CURRENT >> "${HISTORY_FILE}" | |
LC_ALL=en_US.UTF-8 | |
CHART=`( cat ${HISTORY_FILE} ; echo 100 ) | /usr/local/bin/spark` | |
echo ${CHART:1:5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment