Is there a better way to browse man pages?
from GnuLinuxDude@lemmy.ml to linux@lemmy.ml on 10 Jul 2024 15:26
https://lemmy.ml/post/17835298

For many, many years now when I want to browse a man page about something I’ll type man X into my terminal, substituting X for whatever it is I wish to learn about. Depending on the manual, it’s short and therefore easy to find what I want, or I am deep in the woods because I’m trying to find a specific flag that appears many times in a very long document. Woe is me if the flag switch is a bare letter, like x.

And let’s say it is x. Now I am searching with /x followed by n n n n n n n n N n n n n n. Obviously I’m not finding the information I want, the search is literal (not fuzzy, nor “whole word”), and even if I find something the manual pager might overshoot me because finding text will move the found line to the top of the terminal, and maybe the information I really want comes one or two lines above.

So… there HAS to be a better way, right? There has to be a modern, fast, easily greppable version to go through a man page. Does it exist?

P.S. I am not talking about summaries like tldr because I typically don’t need summaries but actual technical descriptions.

#linux

threaded - newest

[deleted] on 10 Jul 2024 15:34 next collapse

.

thingsiplay@beehaw.org on 10 Jul 2024 15:46 next collapse

Sorry for my previous comment. I was commenting before reading the entire post and was missing the point. On a sidenote, its often enough and helpful to just list the options with program -h or –help . Sometimes the help option has more information or is easier to understand than the man document.

When I search for options in a man document, I usually try it with putting a dash in front of it as -x or –ignore in example. For really large documents sometimes it can help to add a space before it " -x" or a comma after it "-x, " depending on how its actually written. BTW the man program itself has a builtin help you can show by just pressing h while looking at a document.

OneCardboardBox@lemmy.sdf.org on 10 Jul 2024 15:52 next collapse

As an emacs user, I use M-x man. All my standard keybindings make finding what I need very easy.

Of course, it’s not so fast if you aren’t already in emacs.

thingsiplay@beehaw.org on 10 Jul 2024 15:58 next collapse

I want to mention that one can set the pager for man to be Vim too. Then it would load the document in Vim instead in less for display and navigation. This can be set with option man -P pager or with the environmental variable $MANPAGER or $PAGER . I had set this up in the past with original Vim, but it required some special options for Vim as well. It was nice, but ultimately not needed; so I went back to less. Sometimes less is more.

Edit: Here is how one can use Neovim as the pager:

export MANPAGER='nvim +Man!'

I kind of missed it and will set it to this now. Put this line in the Bash configuration .bashrc and every man document is loaded in Neovim now.

amanneedsamaid@sopuli.xyz on 10 Jul 2024 19:12 collapse

+1, displaying in a Emacs buffer solves any issues I could have. If you’re already ‘in’ Emacs, this will be more frictionless than shell scripts around man

sping@lemmy.sdf.org on 10 Jul 2024 15:57 next collapse

Sorry it’s not a very direct answer but this is one of the many things that make Emacs such a comfortable environment once you’re used to it, which takes … a while.

There is a man command and then of course it’s just more text displayed so you can search and narrow and highlight etc. in the same way you do with any other text. Plus of course there are a few trivial bonuses like links to other man pages being clickable.

It’s all text and Emacs is a text manipulation framework (that naturally includes some editors).

pr06lefs@lemmy.ml on 10 Jul 2024 16:17 next collapse

Kind of off topic, but you know what would be cool? If you had an ‘man explain’ command that would define all the flags/args in a command, like:

man explain rsync --append-verify --progress -avz -e “ssh -p 2222” root@$dip:/sdcard/DCIM/Camera newphonepix

Would give you:

rsync - a fast, versatile, remote (and local) file-copying tool
      --append-verify          --append w/old data in file checksum
      --progress               show progress during transfer
      --archive, -a            archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
      --verbose, -v            increase verbosity
      --compress, -z           compress file data during the transfer
      --rsh=COMMAND, -e        specify the remote shell to use 

etc.

agentsac@lemmy.world on 10 Jul 2024 16:21 next collapse

Like this?

matrixrunner@lemmy.world on 10 Jul 2024 16:23 collapse

Or these?

thingsiplay@beehaw.org on 10 Jul 2024 16:28 next collapse

You can just grep the help output

$ rsync --help 2>&1 | grep -E '^ *(--append-verify|--progress|--archive)'
--archive, -a            archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
--append-verify          --append w/old data in file checksum
--progress               show progress during transfer

So it should be possible to create a simple script to do that. Similarly one can output the man document as text to stdout, which in turn can be grepped. I have no grep command at hand to do this in a useful way:

man grep | col -b
Majestix@lemmy.world on 10 Jul 2024 16:33 next collapse

There is a Plugin for Zsh (ohmyzsh) that gives you that right in the shell. I use it all the time and rely on it. Don’t have the name on my mind though, sorry.

bitfucker@programming.dev on 12 Jul 2024 03:07 collapse

Please do tell once you’ve figured it out.

gomp@lemmy.ml on 10 Jul 2024 17:25 next collapse

Here’s what I get in fish when I start writing a rsync command and hit tab to ask for completions:

❱ rsync --append-verify --progress -avz -
-0  --from0                               (All *from/filter files are delimited by 0s)  --delete                   (Delete files that don’t exist on sender)
-4  --ipv4                                                               (Prefer IPv4)  --delete-after         (Receiver deletes after transfer, not before)
-6  --ipv6                                                               (Prefer IPv6)  --delete-before         (Receiver deletes before transfer (default))
-8  --8-bit-output                          (Leave high-bit chars unescaped in output)  --delete-delay                 (Find deletions during, delete after)
[more lines omitted]
TeddyKila@hexbear.net on 12 Jul 2024 22:31 collapse

Fish does this but is intentionally POSIX noncompliant so you’d wanr to keep the old shell installed if you run other people’s script.

traches@sh.itjust.works on 10 Jul 2024 16:18 next collapse

I’d also like some guidance on this problem (other than “use emacs”), but searching for “ -x” will have a lower false positive rate

jeffreyosborne@lemm.ee on 10 Jul 2024 16:31 next collapse

I like tldr. It doesnt give incredibly in depth explanations, but it does show the basics of using most commands.

underisk@hexbear.net on 10 Jul 2024 19:38 next collapse

tldr.inbrowser.app for anyone curious. There’s also a command line version you can install.

rotopenguin@infosec.pub on 11 Jul 2024 05:39 collapse

I have to remember to use tldr, one of these days. Some manpages get so lost in the pedantry of covering everything that the 99 percentile stuff is buried.

nore@sh.itjust.works on 10 Jul 2024 16:34 next collapse

I’ve had this same situation happen to me before and my solution was to search -x instead of just x.

Rozauhtuno@lemmy.blahaj.zone on 10 Jul 2024 16:37 next collapse

It’s not exactly what you asked for, but the fish shell has often explanations of what each flag does.

RovingFox@infosec.pub on 10 Jul 2024 16:39 next collapse

I use nvchad and pipe the man page into it

kubok@fedia.io on 10 Jul 2024 16:45 next collapse

I have krunner with the man plugin enabled. When typing man:X in the krunner prompt, a window opens with a nicely styled man page.

JRepin@lemmy.ml on 10 Jul 2024 19:25 collapse

Even quicker is “#X”

kubok@fedia.io on 11 Jul 2024 04:30 collapse

I did not know that. Thank you.

ExtimateCookie@hexbear.net on 10 Jul 2024 17:23 next collapse

Still waiting for someone to create Woman

pr06lefs@lemmy.ml on 10 Jul 2024 17:40 next collapse

I picture these pages being inviting and helpful, with maybe ascii art “awk sweet awk” or the like, rather than the current “maintenance locker full of random tools” vibe

hagar@lemmy.ml on 10 Jul 2024 17:56 collapse
vzq@lemmy.blahaj.zone on 10 Jul 2024 17:38 next collapse

Honestly, I usually just “man command” in google.

I know it’s wrong but my browser is tiled next to my terminal and it’s easy to look up stuff.

ParetoOptimalDev@lemmy.today on 11 Jul 2024 12:06 collapse

I did this before being in emacs made it so convenient to avoid, but got bit randomly by different versions or gnu vs BSD.

electricprism@lemmy.ml on 10 Jul 2024 17:59 next collapse

I read man in nvim, there is a alias on the arch wiki IIRC (and syntax highlighting)

troyunrau@lemmy.ca on 10 Jul 2024 18:08 next collapse

In KDE, there used to be man: as a protocol that you could use from Konqueror or anything else for that matter. Does it still exist?

I’m at work and cannot check.

JRepin@lemmy.ml on 10 Jul 2024 19:21 collapse

Yup still exists. It is also available in KDE Help Center. And you can quickly jump to a man page you typing “#man” into KRunner.

PseudoSpock@lemmy.dbzer0.com on 10 Jul 2024 18:10 next collapse

       man -k printf
           Search  the short descriptions and manual page names for the keyword
           printf as regular expression.  Print out any matches.  Equivalent to
           apropos printf.
Obi@sopuli.xyz on 10 Jul 2024 18:44 next collapse

As someone with 0 knowledge of Linux (and very little of programming/command lines in general), this thread reads funny AF.

martinb@lemmy.sdf.org on 12 Jul 2024 05:30 collapse

We are deep in the technical weeds here. 95% of Linux usage really doesn’t require such humour unfortunately.

kbal@fedia.io on 10 Jul 2024 19:15 next collapse

I am searching with /x

On most systems these days you can use regular expressions there. If /-x isn't good enough try /-x[ ,] or whatever.

wargreymon@sh.itjust.works on 10 Jul 2024 20:25 next collapse

info

rotopenguin@infosec.pub on 11 Jul 2024 05:34 collapse

boooooo

wuphysics87@lemmy.ml on 10 Jul 2024 21:05 next collapse

You can search via regex. For instance you know a section heading or flag is the first thing on a line preceded with spaces. I also find it earier to read with extensions for colors.

Schmerzbold@feddit.org on 10 Jul 2024 21:55 next collapse

You can set on what line on the screen less (the pager program man uses by default) puts search results with the -jn/–jump-target=n option. For example, using .5 as a value for n makes less focus the line with the search result on the center of the screen. This should help with your overshoot issue.

Either set the option within less with the - command followed by j.5↵ for the current running instance of less, or set and export the LESS environment variable inside your ~/.bashrc to have less always behave that way.

Andy@programming.dev on 11 Jul 2024 00:04 next collapse

As someone else said, setting less’ jump value is helpful.

Another tool I use, mostly for the zshall manpage, is github.com/kristopolous/mansnip

MrSoup@lemmy.zip on 11 Jul 2024 03:12 next collapse

Bonus:
You can open man pages inside GNOME Help by using yelp man:X

jbk@discuss.tchncs.de on 11 Jul 2024 05:26 next collapse

wow I kept opening man:somethingwithoutsectionunfortunately in firefox instead of doing that lol

e8d79@discuss.tchncs.de on 11 Jul 2024 15:08 collapse

For KDE users, this also works with khelpcenter.

princessnorah@lemmy.blahaj.zone on 12 Jul 2024 11:29 collapse

Thank you, that’s awesome.

ParetoOptimalDev@lemmy.today on 11 Jul 2024 12:03 next collapse

woman in emacs.

I also find info pages much nicer to use after an adjustment period given I grew up on vim and man.

crispy_kilt@feddit.de on 12 Jul 2024 11:41 collapse

Nice operating system. Just lacks a good editor

GadgeteerZA@fedia.io on 11 Jul 2024 14:43 next collapse

@GnuLinuxDude maybe something like Tkman at https://sourceforge.net/projects/tkman/? Or web based like https://linux.die.net/man/ or https://man7.org/linux/man-pages/index.html.

jazztickets@lemmy.world on 11 Jul 2024 15:27 next collapse

I always add a space or two before the flag: / -x

Tovervlag@feddit.nl on 11 Jul 2024 17:40 next collapse

I lately often use chatgpt for these kind of things. It’s amazing in breaking down the parameters and what they mean. Verify, especially when the problem is hard and apparently unfindable. Chatgpt won’t find it either. It sometimes makes up things in these scenarios.

edit: You guys are allowed to not like my post but it really helps me so why not try it instead of just downvoting.

Asetru@feddit.org on 12 Jul 2024 06:56 collapse

It’s amazing

It sometimes makes up things

xkcd.com/481/

Zucca@sopuli.xyz on 11 Jul 2024 20:32 next collapse

I haven’t used lsp for a while, but it seemed like a good $PAGER.

github.com/dgouders/lsp

bastion@feddit.nl on 12 Jul 2024 03:54 next collapse

Man pages this, man pages that. When will the Linux community start really thinking about woman pages?

Eyck_of_denesle@lemmy.zip on 12 Jul 2024 05:50 next collapse

Woman in emacs

crispy_kilt@feddit.de on 12 Jul 2024 11:40 collapse

What’s a womanual?

bastion@feddit.nl on 12 Jul 2024 15:47 collapse

That’s the point.

I thought it would be clear that we should start calling them womanuals this was a joke.

ssm@lemmy.sdf.org on 12 Jul 2024 07:44 collapse

the / and ? commands in the pagers more and most less implementations should support regular expressions (usually BREs in my experience); which is the same thing grep uses. Consider reading your friendly neighborhood regex formatting manpage, if you are confused. As for easily scrolling, ^G to terminate your search followed by b (or your favorite vi or emacs scrolling bind) to scroll back should be sufficient.

Also, man some-manpage | grep expression works, if you didn’t know.