October 26, 2020

fmt

Everybody loves Markdown, it’s pretty cool to get html from a text file, there are tons of programs that understands is and display it with nice CSS. I personally like to have my markdown files readable from a terminal. Let’s say 80 char per line, let’s say it’s easier on my eyes.

There’s also some studies that says the average human being can focus on a maximum of 50 to 60 characters, 75 at max.

When writing I started to take a look at the current position of the cursor in the line, manually breaking the row up to the next line if it gets too long, but I’m not a machine and it’s pretty annoying to manually rearrange words when the paragraph changes.

Like every boring task someone figured out a way to automate this tedious and frankly pointless activity.

There’s a program called fmt, it’s part of GNU coreutils.

It’s just brilliant.

Just write the file with lines as long as you like, save it and run something like:

fmt -s file.md > file.md.formatted
delete file.md
mv file.md.formatted file.md

Now you got your file formatted and nice to read.

The -s option is the short version of --split-only, which is pretty self explanatory and the man page says:

Split lines only. Do not join short lines to form longer ones. This prevents sample lines of code, and other such “formatted” text from being unduly combined.

Exactly what I wanted.

Take a look at it if you need to format some text in general too, you probably already have it installed as part of coreutils.

© Mauro Scomparin 2020 - 2023

Powered by Hugo & Kiss.