tmux-kanagawa/scripts/cpu_info.sh
Ethan Edwards e290571fee added the refresh rate by pulling from the .tmux.conf file and running
the get_tmux_option function and using that as the variable for the
refresh rate on sleep
2020-08-10 07:57:48 -04:00

42 lines
738 B
Bash
Executable file

#!/usr/bin/env bash
get_tmux_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-option -gqv "$option")
if [ -z $option_value ]; then
echo $default_value
else
echo $option_value
fi
}
get_percent()
{
case $(uname -s) in
Linux)
percent=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
echo $percent
;;
Darwin)
percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}')
echo $percent
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability
;;
esac
}
main()
{
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
cpu_percent=$(get_percent)
echo "CPU $cpu_percent"
sleep $RATE
}
# run main driver
main