I often end up in a situation, where I don't use a command for a while, but then suddenly need to use it; and I need to wade through several help pages until constructing the command line I want. Case in point: occasionally I need to use nmcli
; and then I need to re-check nmcli nm help
and nmcli con help
several times, until I remember what sort of a command I need.
What I have done then, is basically document some of this in a text file; the problem is then I usually save it on Desktop; then every once in a while I clean the Desktop files, so I end up thinking "ah, I don't really use nmcli-examples.txt
all that much, let me move this one elsewhere too"; then when I need it again, I have to issue a find for it first (provided I can remember the file name to look for).
So I was thinking – making a script that: would have a default location set (e.g. ~/customhelp
), where one could keep specifically these kind of reminder text files; and would list the files in that directory upon bash
smart completion for the first command argument; and would open such a file name supplied on the command line either in less
(or in the default GUI text editor if a command line switch is supplied) shouldn't be too difficult.
But I'd rather not try reinventing the wheel, so I was wondering – if any sort of a command for a scheme of usage as described, exists already in a typical GNU/Linux system?
Best Answer
Expanding on the comment by @SamiLaine for using
man
- one reason I didn't like it, was because I expected it to be tedious to set up, and I think this post will show that; but, it seems to work. First, some introduction can be found here:txt2man
(sudo apt-get install txt2man
)First let's create the directory and add it to MANPATH:
Let's test if it is found: close the terminal, open a new terminal; and then:
Unfortunately, this reports nothing for me; even if
echo $MANPATH
says:~/myreminderhelp
.Trying with global
/etc/bash.bashrc
(after deleting the line in local~/.bashrc
, and restarting terminal again):Restart terminal; still
manpath
does not report this directory. Let's now try this:Close and reopen terminal again; finally, we get:
In fact, after finding this, I erased the line from
/etc/bash.bashrc
, andmanpath
still reports the directory. So, I guess editing/etc/manpath.config
is all that is needed.Ok, so let's create an example custom reminder file here:
Then use
txt2man
to get aman
formatted file, and gzip it:Restart terminal again, try typing
man nm
and press TAB - autocompletion showsnmcli-reminder
is not found...So let's try put our files in a
man
section subfolder; the links above indicate section 7 would be appropriate; so:Restart terminal again; try typing
man nm
and press TAB - autocompletion finally works:... but now we have this problem:
Damn it. Could be that currently, our file is
nmcli-reminder.1.gz
indicating section 1 - let's rename it:... and finally the
man
command works!So for this use case, probably it's best to keep the source
.txt
files directly in~/myreminderhelp/
, and then generate man pages in the appropriate subfolder - as in:... the appropriate generation commands for this being:
And here is a
~/myreminderhelp/buildreminders.sh
script:EDIT: Turns out, it is very difficult to get
txt2man
to leave literal source code unformatted, as it tends to auto-extract information likeman
(sub)sections etc. I've modified the script above to usepandoc
instead (via WritingManPages - HerzbubeWiki) -- at least withpandoc
with a Markdown input, you have some control over what is literal preformatted text, and what isn't ...However, both of these tools will indent contents, as is typical for a
man
page (since there, section headings are non-indented, rest of the text content as in paragraphs, is). And I'm not sure I end up liking that all too much...