Watch
1
0
Fork
You've already forked golang-github-noborus-guesswidth
0
No description
  • Go 97.4%
  • Makefile 2.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Daniel Baumann cd8db78da7
Releasing fastforward version 0.5.0-1~ffwd13+u1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2026-07-08 16:52:38 +02:00
.github Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
cmd Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
debian Releasing fastforward version 0.5.0-1~ffwd13+u1. 2026-07-08 16:52:38 +02:00
docs Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
.gitignore Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
.goreleaser.yaml Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
example_test.go Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
go.mod Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
go.sum Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
guesswidth.go Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
guesswidth_test.go Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
LICENSE Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
Makefile Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00
README.md Adding upstream version 0.5.0. 2026-07-08 16:52:21 +02:00

guesswidth

Go Reference Go

Overview

guesswidth guesses the column position for fixed-width formats(fwf).

The output of the ps command has no delimiters, making the values difficult to machine-readable. guesswidth guesses smarter than just space delimiters.

guesswidth is guessed based on the position of characters in the header. So having a header will give you better results.

Install command

There is also a guesswidth command.

go install github.com/noborus/guesswidth/cmd/guesswidth@latest

Guess the width output with no delimiters in the command.

$ ps
    PID TTY          TIME CMD
 302965 pts/3    00:00:12 zsh
 733211 pts/3    00:00:00 ps
 733212 pts/3    00:00:00 tee
 733213 pts/3    00:00:00 guesswidth

Split the output like this:

$ ps | guesswidth
    PID| TTY     |     TIME|CMD
 302965| pts/3   | 00:00:08|zsh
 539529| pts/3   | 00:00:00|ps
 539530| pts/3   | 00:00:00|guesswidth

It can be converted to csv.

$ ps | guesswidth csv
PID,TTY,TIME,CMD
302965,pts/3,00:00:12,zsh
733211,pts/3,00:00:00,ps
733212,pts/3,00:00:00,tee
733213,pts/3,00:00:00,guesswidth
ps | guesswidth --align
   PID|TTY  |    TIME|CMD
302965|pts/3|00:00:12|zsh
733211|pts/3|00:00:00|ps
733212|pts/3|00:00:00|tee
733213|pts/3|00:00:00|guesswidth

Usage

$ guesswidth -h         [~/dev/src/github.com/noborus/guesswidth]
Guess the width of the columns from the header and body,
split them, insert fences and output.

Usage:
  guesswidth [flags]
  guesswidth [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  csv         Output in csv format
  help        Help about any command

Flags:
  -a, --align          align the output
      --fence string   fence (default "|")
      --header int     header line number (default 1)
  -h, --help           help for guesswidth
      --scannum int    number of line to scan (default 100)
      --split int      maximum number of splits (default -1)
  -v, --version        version for guesswidth

Use "guesswidth [command] --help" for more information about a command.

Examples

guesswidth inserts a delimiter (| by default) (Colors are changed here for clarity).

Even if there are spaces in the header or body, they will be separated correctly.

ps

ps

docker ps

docker-ps

docker node

docker node ls