-1

On most machines where I use git, long lines in the output of commands like git diff and git show are wrapped.

On one machine, though, long lines are truncated, and I have to use the left and right arrow keys to scroll the screen horizontally. I don't like this behavior at all, and I need to change it.

I assume this is a configuration variable in git's pager, or something. Does anyone know what it is?

I have seen this inverse question but I haven't been able to infer an answer to my question from it.


Update: I was under the impression that git had its own built-in pager. Experimentation with ps, however, suggests that on the machine where it works properly (does wrap) there's a program /usr/bin/pager running, whereas on the machine where it's "broken" (that is, requires horizontal scrolling), the running pager is less. So perhaps this is a less question, not a git question.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
Steve Summit
  • 45,437
  • 7
  • 70
  • 103
  • "*On one machine, though, long lines are truncated…*" `echo $PAGER` ? `echo $LESS` ? PS. The downvote is not mine (yet). – phd May 24 '22 at 18:38
  • @phd Both variables are empty. – Steve Summit May 24 '22 at 18:39
  • "*On most machines where I use git, long lines … are wrapped.*" The same question, `$PAGER` and `$LESS`? – phd May 24 '22 at 18:40
  • @phd Both empty there also. – Steve Summit May 24 '22 at 18:45
  • `/usr/bin/pager` ? Debian? Check to what alternative `/usr/bin/pager` point on different hosts: `ls -l /usr/bin/pager`; most probably there're different alternatives pager. For example mine are always `less`: `ls -l /usr/bin/pager` -> `/etc/alternatives/pager`; `ls -l /etc/alternatives/pager` -> `/usr/bin/less`. If you have different pagers use `sudo update-alternatives`. – phd May 24 '22 at 18:55
  • @phd Ultimately this is all yak-shaving of the worst kind. Thanks for your help. Thorbjørn has solved it. – Steve Summit May 24 '22 at 18:57
  • I have found that some Linux distributions are terrible in terms of installing multiple weird different pagers. – torek May 25 '22 at 09:50

1 Answers1

3

As it appears that the culprit is less AND the default of less in the source distribution is to wrap lines, this sounds like you have inherited a shell where this has been configured explicitly.

First of all you can toggle this by typing -S at the prompt.

Check for the presence of LESS environment variable, and whether it holds a value containing 'S' (See https://man7.org/linux/man-pages/man1/less.1.html#OPTIONS for the full set of options). If so you need to adapt it to have +S to do the opposite of -S.

On my Mac, this works:

export LESS=+S

Other interesting options are -C which repaints from the top instead of scrolling up (a matter of taste),-N which gives line numbers, and -Q which makes less totally silent.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Setting LESS=+S seems to work. Thank you. (I never use `less` explicitly and so am quite ignorant about it. git's implicit invocation of it has therefore thrust me into a certain amount of unfamiliarity.) – Steve Summit May 24 '22 at 18:55
  • I have made my living at a Unix command prompt on and off for the last 30 years, and `less` was a blessing over `more` back then and is very often the fall-back default if the PAGER environment variable is not defined, so I've learned most of its flags as it is the easiest on the reinstall of the week. If you don't like `git`s default, all of them can be overridden. That said, it is probably relevant that you do this on remote hosts as that probably means you have others preferences to cater to. – Thorbjørn Ravn Andersen May 24 '22 at 19:20
  • I personally prefer the setting "FRX". I've battled systems where there's `more` and `less` that are different programs, `more` and `less` that are the *same* program, and others. I now have a shell script named `more` that picks the right thing to run and if it's `less`, runs `less -FRX "$@"`... – torek May 25 '22 at 09:47
  • Note that you can also export LESS=FRX. When using Git, it will do its own export to set LESS *unless* LESS is already set (!) so that simply setting it to FRX suffices. But the whole "more is sometimes less" thing made that insufficient, hence my script. – torek May 25 '22 at 09:49
  • @torek Well, it is all a matter of taste. I've used systems where the original screen content is restored when less exits, making -F useless, which is probably why you also need X. Raw control characters used to be useful before UTF-8 was everywhere, now ANSI sequences can confuse your display. Thankfully this can be set individually instead of system wide – Thorbjørn Ravn Andersen May 25 '22 at 11:59
  • Yes, that's precisely what `-X` is for, to combat the insane use of ti/te as alternate screen switch. (I also combat this by rebuilding termcap/terminfo on those systems where I can do that.) Meanwhile `-r` allows all escape sequences, `-R` allows selected ones but encodes others, and I prefer `-R` here. – torek May 26 '22 at 00:26
  • @torek Oh, my, goodness. I was about to mention (in response to Thorbjørn's "I have made my living" comment) that for various reasons I had a deep, personal vendetta against`less`, but that this was not the place to go into it — but the main reason was the way it always clears the screen on exit, which has always driven me, well, insane. But somehow I had *never* in all these years discovered that `-X` might be my savior. So thanks for dropping that clue. (Sheesh. At this rate I am never going to convince Thorbjørn that I'm anything other than a hopelessly naïve Unix tyro. :-) ) – Steve Summit May 26 '22 at 01:45
  • @SteveSummit: I consider less's use of ti+te incorrect: they're meant for putting the screen into "editing mode" (vs "viewing mode", for which vs+ve are the sequences) and less isn't an *editor*. So -X makes sense here. But the whole idea of an alternate screen in the first place bugs me. Copying it into xterm, and thence into every subsequent terminal emulator, was in my opinion a mistake (but XTerm had xterm*titeInhibit as a setting). – torek May 26 '22 at 06:05
  • @torek "rebuilding termcap/terminfo" - well, here we differ. I've found it much easier in my professional life to simply work with the tools given and then focus on the actual task I need to do, instead of being annoyed with things working slightly different and doing a lot of work trying to fix that. And then having to do it again when doing the next reinstall.' – Thorbjørn Ravn Andersen May 26 '22 at 09:21
  • @SteveSummit I know other pagers exist (I disliked `pg`, a friend loved `most`, and now `bat` is coming) but it is just a tool. Choose the one you like best by setting an environment variable, or changing the terminal type, and move on. Read the manual page carefully to see how to fine tune it, if things like the screen flipping annoys you, as here, but then thats that. At least to me. – Thorbjørn Ravn Andersen May 26 '22 at 09:25
  • Related link: https://unix.stackexchange.com/questions/tagged/less – Thorbjørn Ravn Andersen May 26 '22 at 09:27