Don't get CPU usage if we're not going to use it

This commit is contained in:
Dylan 2016-03-29 17:11:36 +11:00
parent 97fc5f34b7
commit 059eb0eec0

View file

@ -934,16 +934,17 @@ getcpu () {
# Add CPU info bar # Add CPU info bar
prin "${subtitle}: ${cpu}" prin "${subtitle}: ${cpu}"
cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" if [ "$cpu_display" != "off" ]; then
cpu_usage="${cpu_usage/\.*}%" cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')"
cpu_usage="${cpu_usage/\.*}%"
case "$cpu_display" in case "$cpu_display" in
"info") prin "${subtitle} Usage: ${cpu_usage}" ;; "info") prin "${subtitle} Usage: ${cpu_usage}" ;;
"bar") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} )))" ;; "bar") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} )))" ;;
"infobar") prin "${subtitle} Usage: ${cpu_usage} $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} )))" ;; "infobar") prin "${subtitle} Usage: ${cpu_usage} $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} )))" ;;
"barinfo") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} ))) ${cpu_usage}" ;; "barinfo") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} ))) ${cpu_usage}" ;;
"off") ;; esac
esac fi
[ "$stdout_mode" != "on" ] && unset cpu [ "$stdout_mode" != "on" ] && unset cpu
} }