diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-06-08 15:32:37 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-06-08 15:32:37 +0200 |
| commit | 98934e523c9d05823d7358018017fd880def9716 (patch) | |
| tree | b616428c7bdbc83081ed8e92852aba19e091e458 /src | |
| parent | 6bab41791269c72c7913417e735d06e3e6bf6b56 (diff) | |
| download | sebastiano.tronto.net-98934e523c9d05823d7358018017fd880def9716.tar.gz sebastiano.tronto.net-98934e523c9d05823d7358018017fd880def9716.zip | |
Added blog post. Fixed padding for code in pre.
Diffstat (limited to 'src')
| -rw-r--r-- | src/blog/2022-06-08-more/more.md | 192 | ||||
| -rw-r--r-- | src/blog/blog.md | 1 | ||||
| -rw-r--r-- | src/blog/feed.xml | 7 | ||||
| -rw-r--r-- | src/style-3.css (renamed from src/style-2.css) | 6 |
4 files changed, 205 insertions, 1 deletions
diff --git a/src/blog/2022-06-08-more/more.md b/src/blog/2022-06-08-more/more.md new file mode 100644 index 0000000..3673f59 --- /dev/null +++ b/src/blog/2022-06-08-more/more.md | |||
| @@ -0,0 +1,192 @@ | |||
| 1 | # The man page reading club: more(1) | ||
| 2 | |||
| 3 | In the second episode of this blog series we are going to cover a UNIX | ||
| 4 | pager. Instead of the popular less(1), we are going to check out the | ||
| 5 | classic more(1). | ||
| 6 | |||
| 7 | ## In the bunker | ||
| 8 | |||
| 9 | *After installing your new OS and checking out the basic documentation, | ||
| 10 | you are excited to discover what your laptop can do. But there is | ||
| 11 | something keeping you back. Maybe it's the rumors that the nuclear | ||
| 12 | winter will be raging for years to come and you are in there for the | ||
| 13 | long run. No, it's not that.* | ||
| 14 | |||
| 15 | *You feel that learning is fun, and fun is precious, so you should not | ||
| 16 | waste it. Entertainment is a scarce resource in the bunker: social | ||
| 17 | interactions are awkward, and the battery-charging gym only offers | ||
| 18 | re-runs of crappy mainstream reality shows.* | ||
| 19 | |||
| 20 | *You dedice to play the slow game and | ||
| 21 | [RTFM](https://en.wikipedia.org/wiki/RTFM) some more before doing actual | ||
| 22 | work. You have just found out that the man(1) program calls an external | ||
| 23 | utility, called less(1), to actually display the page. Learning more | ||
| 24 | abut this makes sense.* | ||
| 25 | |||
| 26 | ``` | ||
| 27 | $ man less | ||
| 28 | ``` | ||
| 29 | |||
| 30 | *You start reading, but you soon feel overwhelmed: this manual page is a | ||
| 31 | fucking novel! There are pages and pages of options, and on top of that | ||
| 32 | there are commands, and you can't make sense of what is actually useful. | ||
| 33 | You scroll back to the top of the page and something catches your eyes:* | ||
| 34 | |||
| 35 | ``` | ||
| 36 | less is similar to the traditional more(1), but with many more features. | ||
| 37 | ``` | ||
| 38 | |||
| 39 | *Hoping it will be easier to grasp, you decide to look into more(1)* | ||
| 40 | |||
| 41 | ``` | ||
| 42 | $ man more | ||
| 43 | ``` | ||
| 44 | |||
| 45 | *No, wait! Let's use what we learned [last time](../2022-05-29-man):* | ||
| 46 | |||
| 47 | ``` | ||
| 48 | $ PAGER=more man more | ||
| 49 | ``` | ||
| 50 | |||
| 51 | ## more(1) | ||
| 52 | |||
| 53 | *Follow along at [man.openbsd.org](https://man.openbsd.org/OpenBSD-7.1/more)* | ||
| 54 | |||
| 55 | The description of more(1) starts with | ||
| 56 | |||
| 57 | ``` | ||
| 58 | The more pager displays text one screenful at a time. After showing each | ||
| 59 | screenful, it prompts the user for a command. Most commands scroll the text | ||
| 60 | or move to a different place in the file, while some switch to another file. | ||
| 61 | ``` | ||
| 62 | |||
| 63 | So "commands" seem to be the interesting part. There are also a handful of | ||
| 64 | options, but they seem quite technical and not so interesting. Just to name | ||
| 65 | a few: `-n` changes the number of lines per screenful, `-p` can be used to | ||
| 66 | execute a command when a file is first opened and `-t` can be used to view | ||
| 67 | a file containing a specific "tag". This last one is enticing, but it | ||
| 68 | redirects to ctags(1), which may be a good topic for a future post. | ||
| 69 | |||
| 70 | Let's move on to the juicy part! | ||
| 71 | |||
| 72 | ``` | ||
| 73 | COMMANDS | ||
| 74 | Interactive commands for more are based on vi(1). Some commands may be | ||
| 75 | preceded by a decimal number, called N in the descriptions below. In the | ||
| 76 | following descriptions, ^X means control-X. | ||
| 77 | ``` | ||
| 78 | |||
| 79 | The first command is `h`, which displays a help page for more(1). It is | ||
| 80 | basically a more terse, cheatsheet-like version of the COMMANDS section | ||
| 81 | that we are reading. | ||
| 82 | |||
| 83 | The basic navigation commands scroll the current page up or down. They can | ||
| 84 | all be preceded by the number of lines to be scrolled, but have different | ||
| 85 | defaults: `j` (or `RETURN`) scrolls down one line, `k` up one line. `f` | ||
| 86 | (or `SPACE`, or `^F`) and `b` (or `^B`) scroll one window down and up, | ||
| 87 | respectively. `d` and `u` (or `^D` and `^U`) scroll half a | ||
| 88 | window down and up, respectively. It is not documented in the manual, but | ||
| 89 | arrow keys, and `PgUp` and `PgDn`, seem to work just fine too. | ||
| 90 | |||
| 91 | Perhaps more interestingly, the commands `m` and `'` (single quote) allow | ||
| 92 | you to "mark" certain lines and move to them: | ||
| 93 | |||
| 94 | ``` | ||
| 95 | m Followed by any lowercase letter, marks the current position with that letter. | ||
| 96 | |||
| 97 | ' (Single quote.) Followed by any lowercase letter, returns to the position | ||
| 98 | which was previously marked with that letter. Followed by another single | ||
| 99 | quote, returns to the position at whcih the last "large" movement command was | ||
| 100 | executed, or the beginning of the file if no such movements have occurred. | ||
| 101 | All marks are lost when a new file is examined. | ||
| 102 | ``` | ||
| 103 | |||
| 104 | There is also a search function: | ||
| 105 | |||
| 106 | ``` | ||
| 107 | /pattern Search forward in the file for the N-th line containing the pattern. | ||
| 108 | N defaults to 1. The pattern is a basic regular expression (BRE). | ||
| 109 | See re_format(7) for more information on regular expressions. | ||
| 110 | The search starts at the second line displayed. | ||
| 111 | ``` | ||
| 112 | |||
| 113 | Regular expressions are a powerful tool, but we will not see them in detail | ||
| 114 | today. For now it is enough to know that plain text is a perfectly fine | ||
| 115 | regular expression. | ||
| 116 | |||
| 117 | There are alternative commands for searching: using `?` instead of `/` | ||
| 118 | searches backwards from the top line, while `/!` and `?!` search for lines | ||
| 119 | that *do not* match the pattern. In each case the search command can be | ||
| 120 | preceded by a number `N`, meaning we want to find the `N`-th line that | ||
| 121 | matches the search. I can see this being useful with `N=2` in case you | ||
| 122 | want to find the first next occurrence of a word that appears on the | ||
| 123 | current screen. But it is probably easier to just rely on the `n` and `N` | ||
| 124 | commands, which simply repeat the previous search, in the same or opposite | ||
| 125 | direction respectively; for example, using `N` after a `?` search searches | ||
| 126 | for the same pattern *forward*. | ||
| 127 | |||
| 128 | The next group of commands is used to move between different files: `:e` | ||
| 129 | to open a new one, `:n` for the next file and `:p` for the previous. | ||
| 130 | `:t` is used to move between the aforementioned (but not explained) tags. | ||
| 131 | |||
| 132 | If you are using more to view a file, the command `v` can be used to edit it, | ||
| 133 | using the editor vi(1) by default. | ||
| 134 | |||
| 135 | And finally | ||
| 136 | |||
| 137 | ``` | ||
| 138 | q | :q | ZZ Exits more. | ||
| 139 | ``` | ||
| 140 | |||
| 141 | The last sections are fairly short, but worth skimming through. | ||
| 142 | |||
| 143 | The ENVIRONMENT section explains that more can read some environment | ||
| 144 | variables to change its behavior. In my opionion the most interesting | ||
| 145 | ones are `EDITOR`, which changes the editor to be used with the `v` | ||
| 146 | command, and `MORE`, which can be used to set default options for more. | ||
| 147 | |||
| 148 | An interesting example in the EXAMPLES section: | ||
| 149 | |||
| 150 | ``` | ||
| 151 | Examine several manual pages, starting from the options description in | ||
| 152 | the DESCRIPTION section: | ||
| 153 | |||
| 154 | $ more -p '/DESCRIPTION | ||
| 155 | > /options | ||
| 156 | > ' *.1 | ||
| 157 | ``` | ||
| 158 | |||
| 159 | And a word of warning from the STANDARDS section: | ||
| 160 | |||
| 161 | ``` | ||
| 162 | The more utility is compliant with the IEEE Std 1003.1-2008 ("POSIX.1") specification, | ||
| 163 | though its presence is optional. | ||
| 164 | ``` | ||
| 165 | |||
| 166 | This means that, unfortunately, when dealing with some more obscure POSIX | ||
| 167 | operating system you may not have the luxury of a pager program. Too bad. | ||
| 168 | |||
| 169 | ## Conclusions | ||
| 170 | |||
| 171 | It is worth noting that the more(1) manual page states | ||
| 172 | |||
| 173 | ``` | ||
| 174 | The present implementation is actually less(1) in disguise. | ||
| 175 | ``` | ||
| 176 | |||
| 177 | In practice this means that in OpenBSD, even when using more, one can | ||
| 178 | make full use of the extra features of less described in its manual | ||
| 179 | page. One of the few differences is how certain options are interpreted. | ||
| 180 | |||
| 181 | I originally planned to write about less(1), but I was, as the fictional | ||
| 182 | *you* in the nuclear bunker, overwhelmed by the amount of options | ||
| 183 | available. Most of them are either quite technical or just change | ||
| 184 | slightly the behavior of the pager. Some can be nice, but definitely | ||
| 185 | not necessary (e.g. `-P` to change the prompt). | ||
| 186 | |||
| 187 | I don't see myself using any of the extra features described in the less(1) | ||
| 188 | man page, with the notable exception of the `|` (pipe) command, which | ||
| 189 | can be used to pipe arbitrary portions of the current file to an external | ||
| 190 | command. But apart from this I could easily live in the pre-1985 era. | ||
| 191 | |||
| 192 | See you next time! | ||
diff --git a/src/blog/blog.md b/src/blog/blog.md index 641b3a0..18b1fbe 100644 --- a/src/blog/blog.md +++ b/src/blog/blog.md | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | [RSS Feed](feed.xml) | 3 | [RSS Feed](feed.xml) |
| 4 | 4 | ||
| 5 | * 2022-06-08 [The man page reading club: more(1)](2022-06-08-more) | ||
| 5 | * 2022-06-04 [The gemini protocol](2022-06-04-gemini) | 6 | * 2022-06-04 [The gemini protocol](2022-06-04-gemini) |
| 6 | * 2022-05-29 [The man page reading club: man(1)](2022-05-29-man) | 7 | * 2022-05-29 [The man page reading club: man(1)](2022-05-29-man) |
| 7 | * 2022-05-21 [Blogs](2022-05-21-blogs) | 8 | * 2022-05-21 [Blogs](2022-05-21-blogs) |
diff --git a/src/blog/feed.xml b/src/blog/feed.xml index f7db1ef..d84e8d5 100644 --- a/src/blog/feed.xml +++ b/src/blog/feed.xml | |||
| @@ -9,6 +9,13 @@ Thoughts about software, computers and whatever I feel like sharing | |||
| 9 | </description> | 9 | </description> |
| 10 | 10 | ||
| 11 | <item> | 11 | <item> |
| 12 | <title>The man page reading club: more(1)</title> | ||
| 13 | <link>https://sebastiano.tronto.net/blog/2022-06-08-more</link> | ||
| 14 | <description>The man page reading club: more(1)</description> | ||
| 15 | <pubDate>2022-06-08</pubDate> | ||
| 16 | </item> | ||
| 17 | |||
| 18 | <item> | ||
| 12 | <title>The gemini protocol</title> | 19 | <title>The gemini protocol</title> |
| 13 | <link>https://sebastiano.tronto.net/blog/2022-06-04-gemini</link> | 20 | <link>https://sebastiano.tronto.net/blog/2022-06-04-gemini</link> |
| 14 | <description>The gemini protocol</description> | 21 | <description>The gemini protocol</description> |
diff --git a/src/style-2.css b/src/style-3.css index eac9620..fd4d31f 100644 --- a/src/style-2.css +++ b/src/style-3.css | |||
| @@ -34,7 +34,11 @@ img { | |||
| 34 | 34 | ||
| 35 | code { | 35 | code { |
| 36 | background-color: #eeeeee; | 36 | background-color: #eeeeee; |
| 37 | padding: 2px; | 37 | padding: 2px; |
| 38 | } | ||
| 39 | |||
| 40 | pre code { | ||
| 41 | padding: 0px; | ||
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | pre { | 44 | pre { |
