Skip to content

Commit 7010e59

Browse files
committed
add gpu_name and ip
1 parent 98d7871 commit 7010e59

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Enables displaying CPU and GPU information in Tmux `status-right` and `status-le
44
Configurable percentage and icon display.
55

66
## Installation
7+
78
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
89

910
Add plugin to the list of TPM plugins in `.tmux.conf`:
1011

1112
```shell
12-
set -g @plugin 'tmux-plugins/tmux-cpu'
13+
set -g @plugin 'tmux-plugins/tmux-hardware'
1314
```
1415

1516
Hit `prefix + I` to fetch the plugin and source it.
@@ -21,7 +22,7 @@ If format strings are added to `status-right`, they should now be visible.
2122
Clone the repo:
2223

2324
```shell
24-
$ git clone https://github.com/tmux-plugins/tmux-cpu ~/clone/path
25+
$ git clone https://github.com/tmux-plugins/tmux-hardware ~/clone/path
2526
```
2627

2728
Add this line to the bottom of `.tmux.conf`:
@@ -42,13 +43,13 @@ If format strings are added to `status-right`, they should now be visible.
4243
### Optional requirements (Linux, BSD, OSX)
4344

4445
- `iostat` or `sar` are the best way to get an accurate CPU percentage.
45-
A fallback is included using `ps -aux` but could be inaccurate.
46+
A fallback is included using `ps -aux` but could be inaccurate.
4647
- `free` is used for obtaining system RAM status.
4748
- `lm-sensors` is used for CPU temperature.
4849
- `nvidia-smi` is required for GPU information.
49-
For OSX, `cuda-smi` is required instead (but only shows GPU memory use rather than load).
50-
If "No GPU" is displayed, it means the script was not able to find `nvidia-smi`/`cuda-smi`.
51-
Please make sure the appropriate command is installed and in the `$PATH`.
50+
For OSX, `cuda-smi` is required instead (but only shows GPU memory use rather than load).
51+
If "No GPU" is displayed, it means the script was not able to find `nvidia-smi`/`cuda-smi`.
52+
Please make sure the appropriate command is installed and in the `$PATH`.
5253

5354
## Usage
5455

@@ -77,6 +78,7 @@ This is done by introducing 12 new format strings that can be added to
7778
- `#{cpu_temp}` - will show CPU temperature (averaged across cores)
7879
- `#{cpu_temp_bg_color}` - will change the background color based on the CPU temperature
7980
- `#{cpu_temp_fg_color}` - will change the foreground color based on the CPU temperature
81+
- `#{host_ip}` - will change the ip of hostname
8082

8183
GPU equivalents also exist:
8284

@@ -92,6 +94,7 @@ GPU equivalents also exist:
9294
- `#{gpu_temp}` - will show GPU temperature (average across devices)
9395
- `#{gpu_temp_bg_color}` - will change the background color based on the GPU temperature
9496
- `#{gpu_temp_fg_color}` - will change the foreground color based on the GPU temperature
97+
- `#{gpu_name}` - will change the name of GPU
9598

9699
## Examples
97100

cpu.tmux

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ cpu_interpolation=(
2929
"\#{gpu_temp_icon}"
3030
"\#{gpu_temp_bg_color}"
3131
"\#{gpu_temp_fg_color}"
32+
"\#{gpu_name}"
33+
"\#{host_ip}"
3234
)
3335
cpu_commands=(
3436
"#($CURRENT_DIR/scripts/cpu_percentage.sh)"
@@ -55,6 +57,8 @@ cpu_commands=(
5557
"#($CURRENT_DIR/scripts/gpu_temp_icon.sh)"
5658
"#($CURRENT_DIR/scripts/gpu_temp_bg_color.sh)"
5759
"#($CURRENT_DIR/scripts/gpu_temp_fg_color.sh)"
60+
"#($CURRENT_DIR/scripts/gpu_name.sh)"
61+
"#($CURRENT_DIR/scripts/host_ip.sh)"
5862
)
5963

6064
set_tmux_option() {

scripts/gpu_name.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
5+
# shellcheck source=scripts/helpers.sh
6+
source "$CURRENT_DIR/helpers.sh"
7+
8+
print_gpu_name() {
9+
10+
if command_exists "nvidia-smi"; then
11+
loads=$(cached_eval nvidia-smi)
12+
elif command_exists "cuda-smi"; then
13+
loads=$(cached_eval cuda-smi)
14+
else
15+
echo "No GPU"
16+
return
17+
fi
18+
gpu_name=$(echo "$loads" | nvidia-smi | grep -Eo "NVIDIA\s+\w+\s+\w+\s[0-9]+")
19+
gpu_nums=$(nvidia-smi --query-gpu=count --format=csv,noheader)
20+
if [ ${gpu_nums} -eq 1 ]; then
21+
echo ${gpu_name}
22+
else
23+
echo "${gpu_name}${gpu_nums}"
24+
fi
25+
}
26+
27+
main() {
28+
print_gpu_name
29+
}
30+
main "$@"

scripts/host_ip.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
5+
# shellcheck source=scripts/helpers.sh
6+
source "$CURRENT_DIR/helpers.sh"
7+
8+
print_host_ip() {
9+
# 判断系统类型
10+
if [[ "$(uname)" == "Linux" ]]; then
11+
host_ip=$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
12+
elif [[ "$(uname)" == "Darwin" ]]; then
13+
host_ip=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | head -n 1)
14+
else
15+
echo "Unsupported operating system"
16+
fi
17+
echo ${host_ip}
18+
}
19+
20+
main() {
21+
print_host_ip
22+
}
23+
main "$@"

0 commit comments

Comments
 (0)