Center text with fmt and make ============================= fmt --- For years, plain text was the dominating format on Unix systems. To work with plain text files an ecosystem of powerful utilities evolved. fmt is one of those tools. fmt can do some nifty things with plain text. Using ed to edit my .plan file ------------------------------ Currently I edit my .plan file with Emacs, and then scp it over to the box where it is served by finger. It seems more logical to do the editing directly on that system. But it is overkill to install Emacs for that. So I looked at a way to do that with one of the text utilities. fmt can center lines. Empty lines are centered by a number of spaces, from the left margin to the center of the line. Which means that I can write the content in ed, and use empty lines to add some vertical space. fmt command ----------- The fmt command to center the lines uses two switches: * switch "-w" to set line length * switch "-c" to set line centering The command will therefor be something like this: fmt -w 65 -c input-file > output-file Makefile -------- Because we want a nice header above the text, the construction of the final .plan file consists of two commands: cat nice-header > output-file fmt -w 65 -c input-file >> output-file Typing two lines is of course out of the question, we need a Makefile for that! Here is the Makefile: .plan: plan-header plan-content cat plan-header > .plan fmt -w 65 -c plan-content >> .plan The lines below the first start with a tab (\t). We this we can edit the contents of the .plan file with ed, and run 'make' to construct the new version of the file. Automagically add the date -------------------------- Now that we have automated the creation of the .plan file, it is nice to extend this with automatic adding the current date to the file. This is quite easy: date -I | fmt -w 65 -c >> .plan Let us add this to the Makefile: .plan: plan-header plan-content cat plan-header >.plan fmt -w 65 -c plan-content >>.plan date -I | fmt -w 65 -c >> .plan Don't forget that the lines below the first one all start with a tab (\t). Version control --------------- Having a Makefile, version control can be made effortless. We use RCS for our version control. Normally RCS is used interactively, but RCS can handle batch check ins. We use the following command for this: ci -q -t- -l -m'automatic check in' .plan First, create a subdirectory named "RCS", then RCS will put the version control file there. Let us add this to the Makefile: .plan: plan-header plan-content cat plan-header >.plan fmt -w 65 -c plan-content >>.plan date -I | fmt -w 65 -c >> .plan ci -q -t- -l -m'automatic check in' .plan This gives us a nice history of our .plan file. Some useful RCS commands: rlog .plan This shows the version history. rcsdiff -r1.3 -r1.1 .plan This shows a diff between version 1.3 and version 1.1. co -r1.1 .plan Revert to version 1.1 of the file Result ------ We have setup a .plan file that we can edit in ed. The file has nicely looking centered lines. A new version of the .plan file will be automagically dated with the date of construction. The .plan file is automagically checked in into RCS. This builds a nice history of the changes in our .plan file. We can do all this on the actual system that runs the finger daemon. After issuing the 'make' command, we are done, no scp is involved. See the result at: finger matto@box.matto.nl Last edited: $Date: 2023/08/04 07:51:16 $