Piping a man page on MacOS into an editor

editorsio-redirectionmanosxpipe

Using bash on Mac OS to edit some man pages for my own use.

In Mac OS the command open -t filename will open the specified file in the system's default text editor.

$ man somepage | col -b

will properly render the designated man page. What I want to do is open the rendered man page in the text editor. I can accomplish this as follows:

man somepage | col -b > filename && open -t filename

I should probably be happy with that, but I got it in my brain that there must be a "better way" to do this using only piping and redirect. Also, the command above tends to "litter" my file system with files that I may not need to retain – and therefore requires another step to delete the cruft. Ideally, I could open the rendered man page in the editor without a file name, or some generic filename that would be overwritten on each invocation. I've spent about an hour now noodling over this, trying different things, to no avail.

What made most sense to me was this:

$ open -t < man somepage | col -b

or this:

$ open -t &1 < man somepage | col -b

but of course that doesn't work because the shell takes man as the filename. Am I even close to getting this right? Am I daft for trying?

Best Answer

You can pass open the -f flag to have it read the contents from stdin and open them in the text editor, which makes it usable in a pipeline.

So something like this should do what you want:

man somepage | col -b | open -tf

See also:

Related Question