6

Like many (most), I use git, which by default sends its output (for diffs, logs, etc.) to less, with the options -FRSX. The options are overrideable in .gitconfig by setting the pager to be called with overriding options. E.g.:

  pager=less -F -+S

When I set less to quit after less than one screen of output and not truncate lines (i.e. less -F -+S as in the example above), I get automatically returned to my command prompt after I run (say) a log command.

However, if I do have it chop lines (i.e. use only less -F), and any lines get truncated, then when it ends, it doesn't quit immediately, but prints END and waits for me to press Q, which is somewhat annoying.

(Note that the problematic behaviour does not happen if no lines are truncated because they are all narrower than my terminal. The problem is not occurring because it is asked to truncate the lines, but that it is actually doing so.)

Is there a way to chop lines and still exit from less automatically after less than a screen?

2 Answers 2

7

Well... that would be against the idea of paging... wouldn't it? :-)

But to answer your question: I'm pretty sure there isn't. This is from the source code of less:

/*
 * The char won't fit in the line; the line
 * is too long to print in the screen width.
 * End the line here.
 */
if (chopline || hshift > 0)  <--- you have chop lines (-S)
{
        ...
        quit_if_one_screen = FALSE;    <--- this resets -F
}

Sorry :-)

7
  • Huh, I wonder why.
    – Wilson F
    Commented Sep 22, 2015 at 23:45
  • Also, can you clarify, "that would be against the idea of paging", please? I'm not sure I follow.
    – Wilson F
    Commented Sep 22, 2015 at 23:45
  • Paging is by definition the ability to scroll around when something doesn't fit on the screen and this doesn't. It can be argued whether it's only for "pages" (i.e. lines) but I guess we are not there any more.
    – V13
    Commented Sep 22, 2015 at 23:49
  • Does less support left/right scrolling?
    – Wilson F
    Commented Sep 22, 2015 at 23:52
  • 1
    Yes. When there's horizontal overflow with -S, try pressing the right arrow key or Esc-) / Esc-(. If you press h while in less it will show the help for this.
    – V13
    Commented Sep 22, 2015 at 23:54
0

Since less effectively disables --quit-if-one-screen when any line is truncated by chop-long-lines, you can't solve this with less alone. One alternative it to truncate the lines before passing them to less. Something like this:

pager = "cut -c -512 | less --quit-if-one-screen"

Or, if you want to make it vary according to your terminal width:

pager = "cut -c -$COLUMNS | less --quit-if-one-screen"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .