2020-06-01 08:10:10 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-08-10 14:04:51 +02:00
|
|
|
# function for getting the refresh rate
|
2020-08-10 13:57:48 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-06-01 08:10:10 +02:00
|
|
|
get_percent()
|
|
|
|
{
|
2020-06-03 04:55:14 +02:00
|
|
|
case $(uname -s) in
|
2020-06-01 08:10:10 +02:00
|
|
|
Linux)
|
2020-08-31 11:41:45 +02:00
|
|
|
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
|
2020-06-01 08:10:10 +02:00
|
|
|
echo $percent
|
|
|
|
;;
|
|
|
|
|
2020-06-04 04:58:26 +02:00
|
|
|
Darwin)
|
2020-06-01 16:39:17 +02:00
|
|
|
percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}')
|
2020-06-01 17:53:16 +02:00
|
|
|
echo $percent
|
2020-06-01 08:10:10 +02:00
|
|
|
;;
|
|
|
|
|
2020-06-04 04:58:26 +02:00
|
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
2020-06-01 08:10:10 +02:00
|
|
|
# TODO - windows compatability
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2020-08-10 14:04:51 +02:00
|
|
|
# storing the refresh rate in the variable RATE, default is 5
|
2020-08-10 13:57:48 +02:00
|
|
|
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
|
2020-06-03 04:55:14 +02:00
|
|
|
cpu_percent=$(get_percent)
|
2020-06-01 08:10:10 +02:00
|
|
|
echo "CPU $cpu_percent"
|
2020-08-09 07:50:07 +02:00
|
|
|
sleep $RATE
|
2020-06-01 08:10:10 +02:00
|
|
|
}
|
2020-06-04 04:58:26 +02:00
|
|
|
|
|
|
|
# run main driver
|
2020-06-01 08:10:10 +02:00
|
|
|
main
|