sebastiano.tronto.net

Source files and build scripts for my personal website
git clone https://git.tronto.net/sebastiano.tronto.net
Download | Log | Files | Refs | README

commit a2221e45c763113339bc73abf53f0c5dbddba609
parent 2fac5adf65322b43d4ebba9766a2e0a3412df3c9
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Mon,  5 Sep 2022 21:41:01 +0200

Added blog post

Diffstat:
Msrc/blog/2022-05-29-man/man.md | 15+++++++++++++++
Asrc/blog/2022-09-05-man-col/man-col.md | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/blog/blog.md | 1+
Msrc/blog/feed.xml | 7+++++++
4 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/src/blog/2022-05-29-man/man.md b/src/blog/2022-05-29-man/man.md @@ -246,3 +246,18 @@ here, such as `less(1)`, or dive into more exciting stuff with something like `sh(1)`. Stay tuned! + +## Update 2022-09-05 + +In [a more recent blog post](../2022-09-05-man-col) I comment on a part +of the manual that I skipped, although it is actually useful for writing +these blog entries: + +``` +When using -c, most terminal devices are unable to show the +markup. To print the output of man to the terminal with markup +but without using a pager, pipe it to ul(1). To remove the +markup, pipe the output to col(1) -b instead. +``` + +If you are curious, check the [new post](../2022-09-05-man-col)! diff --git a/src/blog/2022-09-05-man-col/man-col.md b/src/blog/2022-09-05-man-col/man-col.md @@ -0,0 +1,74 @@ +# Pipe man into col -b to get rid of ^H + +The man page reading club is returning soon. In the meantime, +here is a short post on a trick related to `man` itself that I skipped in the +[first post of the series](../2022-05-29-man). + +## Vi rocks + +A cool feature of vi-like editors is that you can insert the +output a command in the file you are editing, without doing any awkard +copy-pasting. You can do this with the `r` ex command: + +``` +:r !date +``` + +Inserts the output of the `date` command on a new line. You can also +use the `!` (bang) command, combined with a motion, to feed the +text between the cursor and the target of the motion to a command and +replace it with the output of the command itself. For example +I often use `!}fmt` to format the next paragraph when I am writing +an email. + +## Man pages and ANSI escape codes + +Unfortunately, if you try to use this feature to include parts of a man page, +you might not like the result. Typing `:r !man man | head` gives + +``` +MAN(1) General Commands Manual MAN(1) + +N^HNA^HAM^HME^HE + m^Hma^Han^Hn - display manual pages + +S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS + 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] + [[-^H-s^Hs] _^Hs_^He_^Hc_^Ht_^Hi_^Ho_^Hn] _^Hn_^Ha_^Hm_^He _^H._^H._^H. + +D^HDE^HES^HSC^HCR^HRI^HIP^HPT^HTI^HIO^HON^HN +``` + +Not cool! This happens because manual pages are not made of plain text. They +contain *ANSI escape codes* to provide some basic formatting, like +bold text and whatnot (you might or might not see them, depending on the +capabilities of your terminal emulator). This is a complex topic and I don't +know much about it. Check out the excellent post +[Anatomy of a Terminal Emulator](https://poor.dev/terminal-anatomy) +by [poor.dev](https://poor.dev) if you want to learn more. + +Long story short, the workaround is included in the man page itself: + +``` +When using -c, most terminal devices are unable to show the +markup. To print the output of man to the terminal with markup +but without using a pager, pipe it to ul(1). To remove the +markup, pipe the output to col(1) -b instead. +``` + +Indeed, using `:r !man man | col -b | head` gives: + +``` +MAN(1) General Commands Manual MAN(1) + +NAME + man - display manual pages + +SYNOPSIS + man [-acfhklw] [-C file] [-M path] [-m path] [-S subsection] + [[-s] section] name ... + +DESCRIPTION +``` + +Hooray! diff --git a/src/blog/blog.md b/src/blog/blog.md @@ -2,6 +2,7 @@ [RSS Feed](feed.xml) +* 2022-09-05 [Pipe man into col -b to get rid of ^H](2022-09-05-man-col) * 2022-08-14 [How I update my website](2022-08-14-website) * 2022-07-07 [The man page reading club: shutdown(8)](2022-07-07-shutdown) * 2022-06-12 [The UNIX shell as an IDE: look stuff up with sed](2022-06-12-shell-ide-sed) diff --git a/src/blog/feed.xml b/src/blog/feed.xml @@ -9,6 +9,13 @@ Thoughts about software, computers and whatever I feel like sharing </description> <item> +<title>Pipe man into col -b to get rid of ^H</title> +<link>https://sebastiano.tronto.net/blog/2022-09-05-man-col</link> +<description>Pipe man into col -b to get rid of ^H</description> +<pubDate>2022-09-05</pubDate> +</item> + +<item> <title>How I update my website</title> <link>https://sebastiano.tronto.net/blog/2022-08-14-website</link> <description>How I update my website</description>