Principal engineer at Mercury. I've authored the Dhall configuration language, the Haskell for all blog, and countless packages and keynote presentations.
I'm a midwife to the hidden beauty in everything.
💖 @wiredaemon
It's basically like a much better version of the fold command for wrapping text:
It reflows text that already has line breaks
… instead of preserving those line breaks like fold does
It supports a soft column limit and a hard column limit
… whereas fold only supports a hard column limit
It uses a more intelligent layout algorithm
It will actually look ahead when deciding where to split text to make paragraphs look less ragged.
It preserves indentation!
It wraps at word boundaries by default
… whereas with fold you have to opt into this using -s
Best of all, fmt is widely available! Both fold and fmt are part of the GNU coreutils package, so if you have fold on your system you likely have fmt installed, too.
A little known fact is that if you define a Bash function with parentheses instead of braces, like this:
foo () (
x=1
)
… then the variables defined within that function are lexically scoped:
$ foo
$ declare -p x
declare: no such variable: x
I learned this trick from the following blog post: