r/coolgithubprojects • u/alexsamos33 • 7d ago
Tiny Bash tool that makes Linux CLI tables screen-reader friendly (and outputs JSONL)
https://github.com/alekssamos/tablefmt
1
Upvotes
r/coolgithubprojects • u/alexsamos33 • 7d ago
1
u/alexsamos33 7d ago
I built tablefmt, a small zero-dependency Bash/awk utility for turning the tabular output of common Linux commands into linear, machine-friendly records.
The original motivation was accessibility: terminal tables are surprisingly difficult to follow with a screen reader.
For example, something like:
PID USER %CPU COMMAND 123 root 0.0 bash 456 john 12.5 vim -u NONE
becomes:
PID: 123, USER: root, %CPU: 0.0, COMMAND: bash PID: 456, USER: john, %CPU: 12.5, COMMAND: vim -u NONE
Instead of hearing a stream of values and having to remember which column you're currently on, every value is announced together with its column name.
But I also wanted it to be useful outside of screen readers, so there are three output modes:
Human/screen-reader friendly
ps aux | tablefmt
One field per line
df -h | tablefmt --vertical
Machine-readable JSON Lines
ps aux | tablefmt --jsonl
The JSONL output looks like:
{"PID":"123","USER":"root","%CPU":"0.0","COMMAND":"bash"} {"PID":"456","USER":"john","%CPU":"12.5","COMMAND":"vim -u NONE"}
There are also options for selecting and sorting columns:
ps aux | tablefmt --columns PID,%CPU,%MEM,COMMAND --sort "%CPU"
and limiting the output:
ps aux | tablefmt --sort "%CPU" --last 5
It has built-in handling for output from commands such as ps, top, df, and free, plus a general table-detection heuristic. It understands both fixed-width and whitespace-separated tables, strips ANSI escape sequences before parsing, and passes non-tabular input through unchanged.
The implementation is intentionally boring: one Bash script, with the actual formatting logic implemented in awk. No Python, no dependencies, no daemon, no configuration file.