@@ -4,29 +4,32 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
4
5
5
source " $CURRENT_DIR /helpers.sh"
6
6
7
+ cpu_percentage_format=" %3.1f%%"
8
+
7
9
print_cpu_percentage () {
10
+ cpu_percentage_format=$( get_tmux_option " @cpu_percentage_format" " $cpu_percentage_format " )
8
11
9
12
if command_exists " iostat" ; then
10
13
11
14
if is_linux_iostat; then
12
- iostat -c 1 2 | sed ' /^\s*$/d' | tail -n 1 | awk ' {usage=100-$NF} END {printf("%3.1f%%" , usage)}' | sed ' s/,/./'
15
+ iostat -c 1 2 | sed ' /^\s*$/d' | tail -n 1 | awk -v format= " $cpu_percentage_format " ' {usage=100-$NF} END {printf(format , usage)}' | sed ' s/,/./'
13
16
elif is_osx; then
14
- iostat -c 2 disk0 | sed ' /^\s*$/d' | tail -n 1 | awk ' {usage=100-$6} END {printf("%3.1f%%" , usage)}' | sed ' s/,/./'
17
+ iostat -c 2 disk0 | sed ' /^\s*$/d' | tail -n 1 | awk -v format= " $cpu_percentage_format " ' {usage=100-$6} END {printf(format , usage)}' | sed ' s/,/./'
15
18
elif is_freebsd || is_openbsd; then
16
- iostat -c 2 | sed ' /^\s*$/d' | tail -n 1 | awk ' {usage=100-$NF} END {printf("%3.1f%%" , usage)}' | sed ' s/,/./'
19
+ iostat -c 2 | sed ' /^\s*$/d' | tail -n 1 | awk -v format= " $cpu_percentage_format " ' {usage=100-$NF} END {printf(format , usage)}' | sed ' s/,/./'
17
20
else
18
21
echo " Unknown iostat version please create an issue"
19
22
fi
20
23
elif command_exists " sar" ; then
21
- sar -u 1 1 | sed ' /^\s*$/d' | tail -n 1 | awk ' {usage=100-$NF} END {printf("%3.1f%%" , usage)}' | sed ' s/,/./'
24
+ sar -u 1 1 | sed ' /^\s*$/d' | tail -n 1 | awk -v format= " $cpu_percentage_format " ' {usage=100-$NF} END {printf(format , usage)}' | sed ' s/,/./'
22
25
else
23
26
if is_cygwin; then
24
27
usage=" $( WMIC cpu get LoadPercentage | grep -Eo ' ^[0-9]+' ) "
25
- printf " %3.1f%% " $usage
28
+ printf " $cpu_percentage_format " " $usage "
26
29
else
27
30
load=` ps -aux | awk ' {print $3}' | tail -n+2 | awk ' {s+=$1} END {print s}' `
28
31
cpus=$( cpus_number)
29
- echo " $load $cpus " | awk ' {printf "%3.1f%%" , $1/$2}'
32
+ echo " $load $cpus " | awk -v format= " $cpu_percentage_format " ' {printf format , $1/$2}'
30
33
fi
31
34
fi
32
35
}
0 commit comments