Live data from Hacker News

Assorted less(1) tips

blog.thechases.com

31–40 of 56 posts

Re: Assorted less(1) tips

#31
post #21
post #5

Surprised they missed follow! It’s a bit odd to use, but once you get used to it it’s better than tail in many circumstances IMO. `less +F` starts less following stdin or whatever file argument you’ve provided. breaks following, allowing you to search around a business-as-usual `less` session. Hitting `F` (that’s uppercase) starts following again. Yes, you can just start following within a session with `F` too if you…

If you're following a pipe (such as `kubectl logs | less +F`), is sent to all processes in a pipeline, so it stops less from following and it stops the other process entirely. Then you can't start following again with F, or load more data in with G. Less provides an alternative of to stop following, but that is intercepted by most shells.

> Less provides an alternative of to stop following, but that is intercepted by most shells.

WoW, thanks a lot! That was my pain for many years. C-x works in Gnome Console just fine.

Re: Assorted less(1) tips

#32
post #21
post #5

Surprised they missed follow! It’s a bit odd to use, but once you get used to it it’s better than tail in many circumstances IMO. `less +F` starts less following stdin or whatever file argument you’ve provided. breaks following, allowing you to search around a business-as-usual `less` session. Hitting `F` (that’s uppercase) starts following again. Yes, you can just start following within a session with `F` too if you…

If you're following a pipe (such as `kubectl logs | less +F`), is sent to all processes in a pipeline, so it stops less from following and it stops the other process entirely. Then you can't start following again with F, or load more data in with G. Less provides an alternative of to stop following, but that is intercepted by most shells.

By the shell or by the kernel’s terminal discipline or by the terminal emulator? AFAIU the shell is basically out of the picture while `less` is running.

Re: Assorted less(1) tips

#33
post #21

Earlier quoted context omitted.

If you're following a pipe (such as `kubectl logs | less +F`), is sent to all processes in a pipeline, so it stops less from following and it stops the other process entirely. Then you can't start following again with F, or load more data in with G. Less provides an alternative of to stop following, but that is intercepted by most shells.

> Less provides an alternative of to stop following, but that is intercepted by most shells. WoW, thanks a lot! That was my pain for many years. C-x works in Gnome Console just fine.

Funnily enough, it literally tells you right there on the bottom line: “Waiting for data... (^X or interrupt to abort)”. No shame in not noticing, just another case of blindness to long-familliar messages I guess.

Re: Assorted less(1) tips

#34
Don't forget that you can enable syntax highlighting/file rendering(like pdf, markdown) in less with lesspipe https://github.com/wofr06/lesspipe. It is exteremely useful and improves readability a lot. What's nice is that this functionality is typically disabled in pipes, so you can be sure that your script will behave as intended.

Re: Assorted less(1) tips

#35
post #21

Earlier quoted context omitted.

If you're following a pipe (such as `kubectl logs | less +F`), is sent to all processes in a pipeline, so it stops less from following and it stops the other process entirely. Then you can't start following again with F, or load more data in with G. Less provides an alternative of to stop following, but that is intercepted by most shells.

By the shell or by the kernel’s terminal discipline or by the terminal emulator? AFAIU the shell is basically out of the picture while `less` is running.

I can while less is running to background that process using the shell, so the shell is clearly not completely gone.

I might be misremembering, but I think I just had to rebind in zsh to get less working.

Re: Assorted less(1) tips

#36
post #35

Earlier quoted context omitted.

By the shell or by the kernel’s terminal discipline or by the terminal emulator? AFAIU the shell is basically out of the picture while `less` is running.

I can while less is running to background that process using the shell, so the shell is clearly not completely gone. I might be misremembering, but I think I just had to rebind in zsh to get less working.

I think by "out of the picture" PP meant that the shell is not processing the input, not that it has exited.

C-z is not processed by the shell but by the terminal "infrastructure".

You can disable it, or change the key binding, and a lot more, with stty(1).

Re: Assorted less(1) tips

#37
post #35

Earlier quoted context omitted.

By the shell or by the kernel’s terminal discipline or by the terminal emulator? AFAIU the shell is basically out of the picture while `less` is running.

I can while less is running to background that process using the shell, so the shell is clearly not completely gone. I might be misremembering, but I think I just had to rebind in zsh to get less working.

> I can while less is running to background that process using the shell, so the shell is clearly not completely gone.

The shell isn’t gone, but it isn’t active either from what I understand. The function of converting the user’s typing ^Z on a terminal (or a ^Z arriving on the master end of a pseudoterminal) into a SIGTSTP signal to the terminal’s foreground process group is[1] a built-in function of the kernel, much like for ^C and SIGINT or ^\ and SIGQUIT. (The use of ^Z resp. ^C or ^\ specifically, as well as the function being active at all, is configurable via a TTY ioctl wrapped by termios wrapped in turn by `stty susp` resp. `stty intr` or `stty quit`.) So is the default signal action of stopping (i.e. suspending) the process in response to that signal. The shell just sees its waitpid() syscall return and handles the possibility of that having happened due to the process stopping rather than dying (by updating its job bookkeeping, making itself the foreground process group again, and reëntering the REPL).

I am not saying that doing job control by filtering the child’s input would be a bad design in the abstract, and it is how terminal multiplexers work for instance. I admit the idea of kernel-side support for shell job control is pretty silly, it’s just how it’s traditionally done in a Unix system.

[1] https://www.gnu.org/software/libc/manual/html_node/Concepts-...

Re: Assorted less(1) tips

#38
I've been using less for years, still learned a few things from the article and comments. I used less + PCRE (for pattern highlighting) for many years for detailed code analysis. It was a great way to get "down in the weeds" and really explore the code. less' bookmarks were another key microtool in that work.

Re: Assorted less(1) tips

#39
One of the more obscure things OpenBSD man does is provide tags to the pager(less). So you can do things like ":t test" in man ksh and end up right at that section.

However while I think the feature is neat, a clever use of an existing feature, I never use it. I think it is sort of the same as info pages and why the technologically superior solution sort of lost to the stupider simpler man pages. Having a simple uniform interface "press / to search, all information in one document" is far less cognitively distracting than the better system.

And final thoughts: if unfamiliar the bsd's use the mdoc set of troff macros to build semantic man pages. sort of like how latex lets you build semantic documents on the tex typesetting engine. Where linux man pages are usually plain troff. OpenBSD actually went one step further and now uses a specific mandoc program to render them rather than the troff + mdoc macros that was used before.

https://man.openbsd.org/mdoc

Re: Assorted less(1) tips

#40
post #10

Less can be configured with a ~/.lesskey file I have a single line in my config[1] which binds s to back-scroll, so that d and s are right next to each other and I can quickly page up/down with one hand. If you’re on macOS, you may not be able to use this unless you install less from Homebrew, or otherwise replace the default less.[2] [1] https://github.com/jez/dotfiles/blob/master/lesskey#L2 [2] https://apple.stacke…

I also like to bind N to next-file. Really burns my britches that MacOS doesn't have lesskey.
Post reply on HN