1

My shell prompt is two lines long (a fancier version of [%n@%m %~]'$'\n''%#. I have $LESS set to -FX. When I quit less, it leaves a single line at the end of my screen, and since my prompt has two lines, the first line of the less output scrolls outside of the terminal window.

I'd rather lose the last line of the output then the first line.

Is there any solution for this problem?

  • What would you like it to do? Lose the last line instead of the first line? Have the shell not write the first line of its prompt after running less? – Stéphane Chazelas Aug 27 '14 at 21:15
1

The top line of less output scrolls out on top because you print a line at the bottom, causing one line of scrolling. That's the \n in your prompt.

How to avoid this, and still have two lines?

You could write part of the prompt above the mormal command line, instead of using a two line prompt. In a sense, it would be one normal line, and one printed above - outside the normal prompt area (it would require the terminal escape sequences for cursor control).

That would cover the less case by writing over the last output line, as you suggested.
But it would also write over the output of other commands - many of which do not have more output that just this line.

So there needs to be some explicit handling of the two cases, like printing an extra newline in the not-less cases.

It's possible for sure, but would need a lot of manual tweaking to work smooth enough for every-day use...

There are other possible approaches, like changing the terminal scroll area for less, but that get's even more messy.

1

I am aware this is now three years late but my google search brought me here so I thought I would share.

To page a file:

(printf '\n'; cat file.txt) | less -FX

To page the output of another command (for example git log):

git log | (printf '\n'; cat) | less -FX

The output starts with blank line. Then when you quit less, this blank line is lost keeping the first line of the file.

I used this for a git log alias.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.