diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-09-05 21:41:01 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-09-05 21:41:01 +0200 |
| commit | a2221e45c763113339bc73abf53f0c5dbddba609 (patch) | |
| tree | 57c91852b655c9c20903df1e756ae73484d203b3 /src/blog/2022-09-05-man-col | |
| parent | 2fac5adf65322b43d4ebba9766a2e0a3412df3c9 (diff) | |
| download | sebastiano.tronto.net-a2221e45c763113339bc73abf53f0c5dbddba609.tar.gz sebastiano.tronto.net-a2221e45c763113339bc73abf53f0c5dbddba609.zip | |
Added blog post
Diffstat (limited to 'src/blog/2022-09-05-man-col')
| -rw-r--r-- | src/blog/2022-09-05-man-col/man-col.md | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/blog/2022-09-05-man-col/man-col.md b/src/blog/2022-09-05-man-col/man-col.md new file mode 100644 index 0000000..e5f1b44 --- /dev/null +++ b/src/blog/2022-09-05-man-col/man-col.md | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | # Pipe man into col -b to get rid of ^H | ||
| 2 | |||
| 3 | The man page reading club is returning soon. In the meantime, | ||
| 4 | here is a short post on a trick related to `man` itself that I skipped in the | ||
| 5 | [first post of the series](../2022-05-29-man). | ||
| 6 | |||
| 7 | ## Vi rocks | ||
| 8 | |||
| 9 | A cool feature of vi-like editors is that you can insert the | ||
| 10 | output a command in the file you are editing, without doing any awkard | ||
| 11 | copy-pasting. You can do this with the `r` ex command: | ||
| 12 | |||
| 13 | ``` | ||
| 14 | :r !date | ||
| 15 | ``` | ||
| 16 | |||
| 17 | Inserts the output of the `date` command on a new line. You can also | ||
| 18 | use the `!` (bang) command, combined with a motion, to feed the | ||
| 19 | text between the cursor and the target of the motion to a command and | ||
| 20 | replace it with the output of the command itself. For example | ||
| 21 | I often use `!}fmt` to format the next paragraph when I am writing | ||
| 22 | an email. | ||
| 23 | |||
| 24 | ## Man pages and ANSI escape codes | ||
| 25 | |||
| 26 | Unfortunately, if you try to use this feature to include parts of a man page, | ||
| 27 | you might not like the result. Typing `:r !man man | head` gives | ||
| 28 | |||
| 29 | ``` | ||
| 30 | MAN(1) General Commands Manual MAN(1) | ||
| 31 | |||
| 32 | N^HNA^HAM^HME^HE | ||
| 33 | m^Hma^Han^Hn - display manual pages | ||
| 34 | |||
| 35 | S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS | ||
| 36 | m^Hma^Han^Hn [-^H-a^Hac^Hcf^Hfh^Hhk^Hkl^Hlw^Hw] [-^H-C^HC _^Hf_^Hi_^Hl_^He] [-^H-M^HM _^Hp_^Ha_^Ht_^Hh] [-^H-m^Hm _^Hp_^Ha_^Ht_^Hh] [-^H-S^HS _^Hs_^Hu_^Hb_^Hs_^He_^Hc_^Ht_^Hi_^Ho_^Hn] | ||
| 37 | [[-^H-s^Hs] _^Hs_^He_^Hc_^Ht_^Hi_^Ho_^Hn] _^Hn_^Ha_^Hm_^He _^H._^H._^H. | ||
| 38 | |||
| 39 | D^HDE^HES^HSC^HCR^HRI^HIP^HPT^HTI^HIO^HON^HN | ||
| 40 | ``` | ||
| 41 | |||
| 42 | Not cool! This happens because manual pages are not made of plain text. They | ||
| 43 | contain *ANSI escape codes* to provide some basic formatting, like | ||
| 44 | bold text and whatnot (you might or might not see them, depending on the | ||
| 45 | capabilities of your terminal emulator). This is a complex topic and I don't | ||
| 46 | know much about it. Check out the excellent post | ||
| 47 | [Anatomy of a Terminal Emulator](https://poor.dev/terminal-anatomy) | ||
| 48 | by [poor.dev](https://poor.dev) if you want to learn more. | ||
| 49 | |||
| 50 | Long story short, the workaround is included in the man page itself: | ||
| 51 | |||
| 52 | ``` | ||
| 53 | When using -c, most terminal devices are unable to show the | ||
| 54 | markup. To print the output of man to the terminal with markup | ||
| 55 | but without using a pager, pipe it to ul(1). To remove the | ||
| 56 | markup, pipe the output to col(1) -b instead. | ||
| 57 | ``` | ||
| 58 | |||
| 59 | Indeed, using `:r !man man | col -b | head` gives: | ||
| 60 | |||
| 61 | ``` | ||
| 62 | MAN(1) General Commands Manual MAN(1) | ||
| 63 | |||
| 64 | NAME | ||
| 65 | man - display manual pages | ||
| 66 | |||
| 67 | SYNOPSIS | ||
| 68 | man [-acfhklw] [-C file] [-M path] [-m path] [-S subsection] | ||
| 69 | [[-s] section] name ... | ||
| 70 | |||
| 71 | DESCRIPTION | ||
| 72 | ``` | ||
| 73 | |||
| 74 | Hooray! | ||
