Live data from Hacker News

Assorted less(1) tips

blog.thechases.com

51–56 of 56 posts

Re: Assorted less(1) tips

#51
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…

> It’s a bit odd to use

I would say it's a bad UX and not just odd. I can't see any benefit to making it modal. It should just load new data as it becomes available without making the user do anything.

Re: Assorted less(1) tips

#52
post #22
post #12

Earlier quoted context omitted.

It would be nice to have a mode that follows in the sense of automatically picking up new output, but that simultaneously would let you navigate around, similar to how terminals behave. Then you’d only need an autoscroll toggle for when you’re at the bottom.

Take a look at "lnav" ...

To elaborate on this, lnav (https://lnav.org) is always polling files to check for new data and will load it in automatically. It does not require the user to do anything.

As far as following the tail of the file: if the focused line is at the end of the file, the display will scroll automatically; otherwise, the display will stick to the current position. Also, if there is a search active, matches in the new data will be found and highlighted.

Re: Assorted less(1) tips

#53
post #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.

You may also have to specify "-R" for less such that ANSI escape sequences are honoured.

(I usually invoke this when viewing jq output, a JSON data formatter / query tool.)

Re: Assorted less(1) tips

#54
post #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.

You may also have to specify "-R" for less such that ANSI escape sequences are honoured. (I usually invoke this when viewing jq output, a JSON data formatter / query tool.)

True. To combat that you can define a variable LESS with default options in your config file. In my case, I have export LESS='-R --quit-if-one-screen -i' (interpret escape sequences, cat input instead of showing it in a pager if it fits on a screen, enable smart-case searching)

Re: Assorted less(1) tips

#55
post #12
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…

It would be nice to have a mode that follows in the sense of automatically picking up new output, but that simultaneously would let you navigate around, similar to how terminals behave. Then you’d only need an autoscroll toggle for when you’re at the bottom.

> autoscroll toggle

This exists on IBM keyboards and is called 'Pause'. Sadly most programs don't use it.

Re: Assorted less(1) tips

#56
post #45

There's a way to make `^q` quit `less` and not clear the screen (like `less -X`), while `q` quits `less` and clears the screen (like normal `less`). 1. Do `echo '^q toggle-option -redraw-screen\nq' >> ~/.config/lesskey` 2. Make sure `less` is invoked without `-X` (or with `-+X` if you want to be sure). This `^q` command is particularly useful for `git log` output and other things where you might need to refer back to…

Actually, it would be more correct to do

    echo '^q toggle-option -redraw-on-quit\nq' >> ~/.config/lesskey
The original version I suggested works too, but by accident. `redraw-on-quit` is the actual option name.

(I'd edit my original message, but it's too late for that)

----

Also, note that if you put `--redraw-on-quit` into your `LESS` config (and not `-X`), and set up `^q` as above, things will still work but with flipped behavior of `q` and `^q`.

If your version of `less` is new enough, I believe that the `--redraw-on-quit` behavior is in every way (slightly) better than the `-X` behavior. In addition to the above, some terminals have special behaviors in alternate screen (like converting mouse wheel to up/down keys), which `--redraw-on-quit` will preserve.

Post reply on HN