mirror of
https://github.com/tmux-plugins/tmux-cpu.git
synced 2026-09-10 07:16:16 -04:00
Add new "cpu_percentage_format" & "gpu_percentage_format" option
This commit is contained in:
parent
befc5d5c58
commit
0e6fb34a3e
|
|
@ -98,6 +98,7 @@ Here are all available options with their default values:
|
|||
@cpu_medium_bg_color "#[bg=yellow]"
|
||||
@cpu_high_bg_color "#[bg=red]"
|
||||
|
||||
@cpu_percentage_format "%3.1f%%" # printf format
|
||||
```
|
||||
|
||||
Same options are valid with `@gpu`
|
||||
|
|
@ -108,6 +109,7 @@ You can can customize each one of these options in your `.tmux.conf`, for exampl
|
|||
|
||||
```shell
|
||||
set -g @cpu_low_fg_color "#[fg=#00ff00]"
|
||||
set -g @cpu_percentage_format "%5.1f%%" # Add left padding
|
||||
```
|
||||
|
||||
Don't forget to reload tmux environment (`$ tmux source-file ~/.tmux.conf`)
|
||||
|
|
|
|||
|
|
@ -4,29 +4,32 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_percentage_format="%3.1f%%"
|
||||
|
||||
print_cpu_percentage() {
|
||||
cpu_percentage_format=$(get_tmux_option "@cpu_percentage_format" "$cpu_percentage_format")
|
||||
|
||||
if command_exists "iostat"; then
|
||||
|
||||
if is_linux_iostat; then
|
||||
iostat -c 1 2 | sed '/^\s*$/d' | tail -n 1 | awk '{usage=100-$NF} END {printf("%3.1f%%", usage)}' | sed 's/,/./'
|
||||
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/,/./'
|
||||
elif is_osx; then
|
||||
iostat -c 2 disk0 | sed '/^\s*$/d' | tail -n 1 | awk '{usage=100-$6} END {printf("%3.1f%%", usage)}' | sed 's/,/./'
|
||||
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/,/./'
|
||||
elif is_freebsd || is_openbsd; then
|
||||
iostat -c 2 | sed '/^\s*$/d' | tail -n 1 | awk '{usage=100-$NF} END {printf("%3.1f%%", usage)}' | sed 's/,/./'
|
||||
iostat -c 2 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
|
||||
else
|
||||
echo "Unknown iostat version please create an issue"
|
||||
fi
|
||||
elif command_exists "sar"; then
|
||||
sar -u 1 1 | sed '/^\s*$/d' | tail -n 1 | awk '{usage=100-$NF} END {printf("%3.1f%%", usage)}' | sed 's/,/./'
|
||||
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/,/./'
|
||||
else
|
||||
if is_cygwin; then
|
||||
usage="$(WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
|
||||
printf "%3.1f%%" $usage
|
||||
printf "$cpu_percentage_format" "$usage"
|
||||
else
|
||||
load=`ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}'`
|
||||
cpus=$(cpus_number)
|
||||
echo "$load $cpus" | awk '{printf "%3.1f%%", $1/$2}'
|
||||
echo "$load $cpus" | awk -v format="$cpu_percentage_format" '{printf format, $1/$2}'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_percentage_format="%3.1f%%"
|
||||
|
||||
print_gpu_percentage() {
|
||||
gpu_percentage_format=$(get_tmux_option "@gpu_percentage_format" "$gpu_percentage_format")
|
||||
|
||||
if command_exists "nvidia-smi"; then
|
||||
loads=$(nvidia-smi)
|
||||
elif command_exists "cuda-smi"; then
|
||||
|
|
@ -16,7 +20,7 @@ print_gpu_percentage() {
|
|||
loads=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)%.*/\1/p')
|
||||
gpus=$(echo "$loads" | wc -l)
|
||||
load=$(echo "$loads" | awk '{count+=$1} END {print count}')
|
||||
echo "$load $gpus" | awk '{printf "%3.0f%%", $1/$2}'
|
||||
echo "$load $gpus" | awk -v format="$gpu_percentage_format" '{printf format, $1/$2}'
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue