A tiny little OS status display. It renders varios OS informations to STDOUT. Its main purpose is to be used inside tmux.
ustat could also be called µicroscopic … from which it derives its name, µstat.
How tiny is tiny? The statically linked binary on Linux is below 60kbyte on disk.
ustat [-h] [mod1] [mod2] [...]
-h - show help (list of modules)
- % - pass through
- nl - newline
- load - system load
- date - date, strftime
- uid - render user id
- user - render user name
- nusers - number of active users
- nproc - number of processes
- ncpus - number of cpus
- bat% - battery level
- bat+h - battery charging, human
- bat+ - battery charging
- cpu% - cpu utilization
- memfh - memory free, human
- memf - memory free
- memr - memory free, ratio
- memh - memory total, human
- mem - memory total
- fsth - filesystem total, human
- fst - filesystem total
- fsr - filesystem ratio
- fsfh - filesystem free, human
- fsf - filesystem free
- fsuh - filesystem used, human
- fsu - filesystem used
- git.branch - git branch
- git.path - git root path
- git.rp - git root path
- tcp6.e - tcp6 established
- tcp6.l - tcp6 listening
- tcp6.c - tcp6 closing
- tcp6 - tcp6 total
- tcp4.e - tcp4 established
- tcp4.l - tcp4 listening
- tcp4.c - tcp4 closing
- tcp4 - tcp4 total
- tcpdump - tcpdump
- tcp.e - tcp established
- tcp.l - tcp listening
- tcp.c - tcp closing
- tcp - tcp total
- coff - color off
- 8# - fg-color, normal
- 8* - fg-color, bright
- B# - bg-color, normal
- B* - bg-color, bright
- 256# - fg-color, 256colors
- 256* - bg-color, 256colors
- rgb# - fg-color, rgb
- rgb* - bg-color, rgb
The git modules take an optional prefix after :. Inside a repo the
prefix is printed before the value, outside a repo neither is:
ustat 'git.branch: on '
- USTAT_BAT_CHARGING - string to display "charging" (default: "^")
- USTAT_BAT_DISCHARGING - string to display "discharging" (default: "v")
- USTAT_SEP - string printed between the arguments (default: none)
ustat collects the values, the shell builds the prompt. With a newline as separator each value lands on its own line, and the shell reads them into an array:
mapfile -t u < <(USTAT_SEP=$'\n' ustat git.branch bat%) # bash
u=("${(@f)$(USTAT_SEP=$'\n' ustat git.branch bat%)}") # zsh
set u (env USTAT_SEP=\n ustat git.branch bat%) # fish
A missing value is printed as is: git.branch is empty outside a repo,
bat% prints - without a battery. The shell decides what to show, and
colors it in its own prompt syntax.
Reference the values in the prompt, don't paste them in. bash and zsh expand the prompt again at every display, and a branch name is chosen by whoever made the repo:
PS1+=' on ${u[0]}' # value is shown
PS1+=" on ${u[0]}" # $(…) in the value runs
Complete prompts: samples/prompt.bash, samples/prompt.zsh,
samples/prompt.fish.
This config line for tmux will show the number of logged in users, the number of processes, the free bytes on / (in human units), the load and the datetime in the bottom right of tmux:
set -g status-right "[#(ustat 'u:' nusers '|p:' nprocs '|/-' fsfh '|l:' load '|' 'date%Y-%m-%d %H:%M:%S]')"
It shows on the right side, from left to right:
- Battery is discharging ("v") (charging would be "^")
- Battery level is 100%
- Number of logged in users: 1
- Number of processes: 220
- Disk free on /: 1644mbyte
- Load is 0.01, 0.04 and 0.00 (see load(3))
- The date is 2024-01-27, 15:10:30 CET
Visible:
- Uptime
- Number of logged in users
- Number of processes
- Disk free on /
- Load
- Time
Font: Victor Mono Nerd
General pre-requisite: You need a C compiler, GCC, CLANG, whatever. I have tested ustat with GCC and CLANG. Others might work as well.
Fetch the source code:
git clone https://github.com/mgumz/ustat
cd ustat
make puts the binary into bin/, named after the compiler's target, e.g.
bin/ustat.linux.aarch64 or bin/ustat.darwin.arm64.
make CFLAGS="-Wno-unused-result"
To get a small static binary:
-
Install https://www.fefe.de/dietlibc/ (on Debian:
apt install dietlibc-dev) -
make ustat.diet
make CFLAGS="-framework IOKit -framework CoreFoundation"
make
If you have CMAKE installed:
mkdir build
cd build
cmake ..
make
The helpers that format numbers have tests in ustat_helper/test_*.c:
make test
With CMAKE, after the build above:
ctest --test-dir build
- https://github.com/i3/i3status
- https://github.com/emersion/i3status-rust
- https://github.com/thewtex/tmux-mem-cpu-load
See LICENSE.md.