mirror of
https://github.com/tmux-plugins/tmux-cpu.git
synced 2026-09-10 07:16:16 -04:00
Merge 6e3236ad72 into bcb110d754
This commit is contained in:
commit
3c29afb580
11
README.md
11
README.md
|
|
@ -156,6 +156,17 @@ set -g @cpu_percentage_format "%5.1f%%" # Add left padding
|
|||
|
||||
Don't forget to reload the tmux environment (`$ tmux source-file ~/.tmux.conf`) after you do this.
|
||||
|
||||
### WSL support
|
||||
|
||||
If you're running on WSL you can set these options to get the CPU / RAM values from the Windows host system instead:
|
||||
|
||||
```shell
|
||||
@cpu_wsl_host 'true' # true/false
|
||||
@ram_wsl_host 'true # true/false
|
||||
```
|
||||
|
||||
Note this only works if `$WSL_DISTRO_NAME` is also set, which is done by default inside WSL.
|
||||
|
||||
### Tmux Plugins
|
||||
|
||||
This plugin is part of the [tmux-plugins](https://github.com/tmux-plugins) organisation. Checkout plugins as [battery](https://github.com/tmux-plugins/tmux-battery), [logging](https://github.com/tmux-plugins/tmux-logging), [online status](https://github.com/tmux-plugins/tmux-online-status), and many more over at the [tmux-plugins](https://github.com/tmux-plugins) organisation page.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ 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 [[ $(get_tmux_option @cpu_wsl_host) == "true" && -n "${WSL_DISTRO_NAME}" ]] ; then
|
||||
load="$(cached_eval wmic.exe cpu get LoadPercentage | grep -Eo '^[0-9]+')"
|
||||
echo "$load" | awk -v format="$cpu_percentage_format" '{printf format, $1}'
|
||||
elif command_exists "iostat"; then
|
||||
|
||||
if is_linux_iostat; then
|
||||
cached_eval 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/,/./'
|
||||
|
|
|
|||
|
|
@ -15,7 +15,15 @@ sum_macos_vm_stats() {
|
|||
print_ram_percentage() {
|
||||
ram_percentage_format=$(get_tmux_option "@ram_percentage_format" "$ram_percentage_format")
|
||||
|
||||
if command_exists "free"; then
|
||||
if [[ $(get_tmux_option @ram_wsl_host) == "true" && -n "${WSL_DISTRO_NAME}" ]] ; then
|
||||
|
||||
# TotalPhysicalMemory is in bytes, but FreePhysicalMemory is in KiB
|
||||
total=$(wmic.exe ComputerSystem get TotalPhysicalMemory | awk '/^[0-9]/{print $1/1024}')
|
||||
free=$(wmic.exe OS get freevirtualmemory | awk '/^[0-9]/{print $1}')
|
||||
used=$(($total - $free))
|
||||
echo "$used $total" | awk -v format="$ram_percentage_format" '{printf(format, 100*$1/$2)}'
|
||||
|
||||
elif command_exists "free"; then
|
||||
cached_eval free | awk -v format="$ram_percentage_format" '$1 ~ /Mem/ {printf(format, 100*$3/$2)}'
|
||||
elif command_exists "vm_stat"; then
|
||||
# page size of 4096 bytes
|
||||
|
|
|
|||
Loading…
Reference in a new issue