Created
August 1, 2025 03:44
-
-
Save jrmdev/a0a90dddae608fd9d5a385d4e9fae171 to your computer and use it in GitHub Desktop.
System info status line for tmux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| userhost="$(whoami)@$(hostname)" | |
| # CPU per-core usage | |
| cpu_usage() { | |
| awk '/^cpu[0-9]/ { | |
| cpu=$1; t=$2+$3+$4+$5+$6+$7+$8; i=$5; | |
| printf "%s,%d,%d\n", cpu, t, i | |
| }' /proc/stat > /tmp/cpu1 | |
| sleep 0.5 | |
| awk '/^cpu[0-9]/ { | |
| cpu=$1; t=$2+$3+$4+$5+$6+$7+$8; i=$5; | |
| cpu_t[cpu]=t; cpu_i[cpu]=i | |
| } | |
| END { | |
| while ((getline < "/tmp/cpu1") > 0) { | |
| split($0,a,","); | |
| cpu=a[1]; t1=a[2]; i1=a[3]; | |
| t2=cpu_t[cpu]; i2=cpu_i[cpu]; | |
| dt=t2 - t1; di=i2 - i1; | |
| if (dt > 0) | |
| printf " %d%%", (dt - di) * 100 / dt | |
| } | |
| }' /proc/stat | |
| } | |
| # Memory usage | |
| mem_usage() { | |
| free -h | awk '/Mem:/ {print $3 "/" $2}' | |
| } | |
| # Disk usage of root filesystem | |
| disk_usage() { | |
| df -h / | awk 'NR==2 {print $3 "/" $2}' | |
| } | |
| # Load average | |
| load_avg() { | |
| uptime | awk -F'load average: ' '{print $2}' | tr -d , | |
| } | |
| # Uptime in days | |
| uptime_days() { | |
| awk '{print int($1/86400) "d"}' /proc/uptime | |
| } | |
| # Compose status line with tmux color formatting | |
| echo "#[fg=red]${userhost}#[default] | #[fg=green]CPU:$(cpu_usage)#[default] | #[fg=cyan]MEM: $(mem_usage)#[default] | #[fg=yellow]DISK: $(disk_usage)#[default] | #[fg=magenta]LOAD: $(load_avg)#[default] | #[fg=blue]UPTIME: $(uptime_days)#[default]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment