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 98934e523c9d05823d7358018017fd880def9716
parent 6bab41791269c72c7913417e735d06e3e6bf6b56
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Wed,  8 Jun 2022 15:32:37 +0200

Added blog post. Fixed padding for code in pre.

Diffstat:
Asrc/blog/2022-06-08-more/more.md | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/blog/blog.md | 1+
Msrc/blog/feed.xml | 7+++++++
Dsrc/style-2.css | 105-------------------------------------------------------------------------------
Asrc/style-3.css | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtop.html | 2+-
6 files changed, 310 insertions(+), 106 deletions(-)

diff --git a/src/blog/2022-06-08-more/more.md b/src/blog/2022-06-08-more/more.md @@ -0,0 +1,192 @@ +# The man page reading club: more(1) + +In the second episode of this blog series we are going to cover a UNIX +pager. Instead of the popular less(1), we are going to check out the +classic more(1). + +## In the bunker + +*After installing your new OS and checking out the basic documentation, +you are excited to discover what your laptop can do. But there is +something keeping you back. Maybe it's the rumors that the nuclear +winter will be raging for years to come and you are in there for the +long run. No, it's not that.* + +*You feel that learning is fun, and fun is precious, so you should not +waste it. Entertainment is a scarce resource in the bunker: social +interactions are awkward, and the battery-charging gym only offers +re-runs of crappy mainstream reality shows.* + +*You dedice to play the slow game and +[RTFM](https://en.wikipedia.org/wiki/RTFM) some more before doing actual +work. You have just found out that the man(1) program calls an external +utility, called less(1), to actually display the page. Learning more +abut this makes sense.* + +``` +$ man less +``` + +*You start reading, but you soon feel overwhelmed: this manual page is a +fucking novel! There are pages and pages of options, and on top of that +there are commands, and you can't make sense of what is actually useful. +You scroll back to the top of the page and something catches your eyes:* + +``` +less is similar to the traditional more(1), but with many more features. +``` + +*Hoping it will be easier to grasp, you decide to look into more(1)* + +``` +$ man more +``` + +*No, wait! Let's use what we learned [last time](../2022-05-29-man):* + +``` +$ PAGER=more man more +``` + +## more(1) + +*Follow along at [man.openbsd.org](https://man.openbsd.org/OpenBSD-7.1/more)* + +The description of more(1) starts with + +``` +The more pager displays text one screenful at a time. After showing each +screenful, it prompts the user for a command. Most commands scroll the text +or move to a different place in the file, while some switch to another file. +``` + +So "commands" seem to be the interesting part. There are also a handful of +options, but they seem quite technical and not so interesting. Just to name +a few: `-n` changes the number of lines per screenful, `-p` can be used to +execute a command when a file is first opened and `-t` can be used to view +a file containing a specific "tag". This last one is enticing, but it +redirects to ctags(1), which may be a good topic for a future post. + +Let's move on to the juicy part! + +``` +COMMANDS + Interactive commands for more are based on vi(1). Some commands may be + preceded by a decimal number, called N in the descriptions below. In the + following descriptions, ^X means control-X. +``` + +The first command is `h`, which displays a help page for more(1). It is +basically a more terse, cheatsheet-like version of the COMMANDS section +that we are reading. + +The basic navigation commands scroll the current page up or down. They can +all be preceded by the number of lines to be scrolled, but have different +defaults: `j` (or `RETURN`) scrolls down one line, `k` up one line. `f` +(or `SPACE`, or `^F`) and `b` (or `^B`) scroll one window down and up, +respectively. `d` and `u` (or `^D` and `^U`) scroll half a +window down and up, respectively. It is not documented in the manual, but +arrow keys, and `PgUp` and `PgDn`, seem to work just fine too. + +Perhaps more interestingly, the commands `m` and `'` (single quote) allow +you to "mark" certain lines and move to them: + +``` +m Followed by any lowercase letter, marks the current position with that letter. + +' (Single quote.) Followed by any lowercase letter, returns to the position + which was previously marked with that letter. Followed by another single + quote, returns to the position at whcih the last "large" movement command was + executed, or the beginning of the file if no such movements have occurred. + All marks are lost when a new file is examined. +``` + +There is also a search function: + +``` +/pattern Search forward in the file for the N-th line containing the pattern. + N defaults to 1. The pattern is a basic regular expression (BRE). + See re_format(7) for more information on regular expressions. + The search starts at the second line displayed. +``` + +Regular expressions are a powerful tool, but we will not see them in detail +today. For now it is enough to know that plain text is a perfectly fine +regular expression. + +There are alternative commands for searching: using `?` instead of `/` +searches backwards from the top line, while `/!` and `?!` search for lines +that *do not* match the pattern. In each case the search command can be +preceded by a number `N`, meaning we want to find the `N`-th line that +matches the search. I can see this being useful with `N=2` in case you +want to find the first next occurrence of a word that appears on the +current screen. But it is probably easier to just rely on the `n` and `N` +commands, which simply repeat the previous search, in the same or opposite +direction respectively; for example, using `N` after a `?` search searches +for the same pattern *forward*. + +The next group of commands is used to move between different files: `:e` +to open a new one, `:n` for the next file and `:p` for the previous. +`:t` is used to move between the aforementioned (but not explained) tags. + +If you are using more to view a file, the command `v` can be used to edit it, +using the editor vi(1) by default. + +And finally + +``` +q | :q | ZZ Exits more. +``` + +The last sections are fairly short, but worth skimming through. + +The ENVIRONMENT section explains that more can read some environment +variables to change its behavior. In my opionion the most interesting +ones are `EDITOR`, which changes the editor to be used with the `v` +command, and `MORE`, which can be used to set default options for more. + +An interesting example in the EXAMPLES section: + +``` +Examine several manual pages, starting from the options description in +the DESCRIPTION section: + + $ more -p '/DESCRIPTION + > /options + > ' *.1 +``` + +And a word of warning from the STANDARDS section: + +``` +The more utility is compliant with the IEEE Std 1003.1-2008 ("POSIX.1") specification, +though its presence is optional. +``` + +This means that, unfortunately, when dealing with some more obscure POSIX +operating system you may not have the luxury of a pager program. Too bad. + +## Conclusions + +It is worth noting that the more(1) manual page states + +``` +The present implementation is actually less(1) in disguise. +``` + +In practice this means that in OpenBSD, even when using more, one can +make full use of the extra features of less described in its manual +page. One of the few differences is how certain options are interpreted. + +I originally planned to write about less(1), but I was, as the fictional +*you* in the nuclear bunker, overwhelmed by the amount of options +available. Most of them are either quite technical or just change +slightly the behavior of the pager. Some can be nice, but definitely +not necessary (e.g. `-P` to change the prompt). + +I don't see myself using any of the extra features described in the less(1) +man page, with the notable exception of the `|` (pipe) command, which +can be used to pipe arbitrary portions of the current file to an external +command. But apart from this I could easily live in the pre-1985 era. + +See you next time! diff --git a/src/blog/blog.md b/src/blog/blog.md @@ -2,6 +2,7 @@ [RSS Feed](feed.xml) +* 2022-06-08 [The man page reading club: more(1)](2022-06-08-more) * 2022-06-04 [The gemini protocol](2022-06-04-gemini) * 2022-05-29 [The man page reading club: man(1)](2022-05-29-man) * 2022-05-21 [Blogs](2022-05-21-blogs) 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>The man page reading club: more(1)</title> +<link>https://sebastiano.tronto.net/blog/2022-06-08-more</link> +<description>The man page reading club: more(1)</description> +<pubDate>2022-06-08</pubDate> +</item> + +<item> <title>The gemini protocol</title> <link>https://sebastiano.tronto.net/blog/2022-06-04-gemini</link> <description>The gemini protocol</description> diff --git a/src/style-2.css b/src/style-2.css @@ -1,105 +0,0 @@ -header nav table { - width: 100%; -} - -.logo img { - max-width: 3em; - margin: 0 0 0 0; -} - -.links { - text-align: right; - font-weight: bold; -} - -footer table { - font-style: italic; - width: 100%; -} - -.hosted { - text-align: right; -} - -body { - margin: auto 8px 20px 8px; -} - -img { - display: block; - margin-left: auto; - margin-right: auto; - max-width: 100%; -} - -code { - background-color: #eeeeee; - padding: 2px; -} - -pre { - background-color: #eeeeee; - border: 2px solid; - padding: 6px; -} - -#blob { - background: #ffffff; - border: none; -} - -a { - color: #0f2899; - text-decoration: none; -} - -.links a { - font-weight: bold; - color: black; -} - -.hosted a, -.contact a { - font-weight: bold; -} - -a:hover { - text-decoration: underline; -} - -html { - margin: 1em auto; - max-width: 42em; -} - -h1 { - text-align: center; -} - -td h1 { - text-align: left; - font-size: 1.5em; -} - -table { - width: 100%; -} - -#files td { - font-family: monospace; - font-size: 1.2em; - min-width: 7em; -} - -#log tr:hover td, -#files tr:hover td { - background-color: #eeeeee; -} - -.url td { - font-family: monospace; -} - -table tr td a img { - min-width: 33px; -} diff --git a/src/style-3.css b/src/style-3.css @@ -0,0 +1,109 @@ +header nav table { + width: 100%; +} + +.logo img { + max-width: 3em; + margin: 0 0 0 0; +} + +.links { + text-align: right; + font-weight: bold; +} + +footer table { + font-style: italic; + width: 100%; +} + +.hosted { + text-align: right; +} + +body { + margin: auto 8px 20px 8px; +} + +img { + display: block; + margin-left: auto; + margin-right: auto; + max-width: 100%; +} + +code { + background-color: #eeeeee; + padding: 2px; +} + +pre code { + padding: 0px; +} + +pre { + background-color: #eeeeee; + border: 2px solid; + padding: 6px; +} + +#blob { + background: #ffffff; + border: none; +} + +a { + color: #0f2899; + text-decoration: none; +} + +.links a { + font-weight: bold; + color: black; +} + +.hosted a, +.contact a { + font-weight: bold; +} + +a:hover { + text-decoration: underline; +} + +html { + margin: 1em auto; + max-width: 42em; +} + +h1 { + text-align: center; +} + +td h1 { + text-align: left; + font-size: 1.5em; +} + +table { + width: 100%; +} + +#files td { + font-family: monospace; + font-size: 1.2em; + min-width: 7em; +} + +#log tr:hover td, +#files tr:hover td { + background-color: #eeeeee; +} + +.url td { + font-family: monospace; +} + +table tr td a img { + min-width: 33px; +} diff --git a/top.html b/top.html @@ -3,7 +3,7 @@ <head> <title> TITLE | Sebastiano Tronto </title> <meta name="viewport" content="width=device-width" /> - <link rel="stylesheet" type="text/css" href="/style-2.css"> + <link rel="stylesheet" type="text/css" href="/style-3.css"> <link rel="icon" href="/favicon.png"> <meta charset="utf-8"> </head>