ydiff icon indicating copy to clipboard operation
ydiff copied to clipboard

Configurable pager behaviour (auto/always/never)

Open shaicoleman opened this issue 6 years ago • 13 comments

ydiff currently uses the --quit-if-one-screen option of less.

Please make the pager behaviour configurable, so the pager can be always enabled or always disabled.

shaicoleman avatar Jan 28 '19 12:01 shaicoleman

I think the default option passed to less -FRSX --shift 1 is sensible, curious what's your use case for disabling -F / --quit-if-one-screen?

ymattw avatar Jan 28 '19 12:01 ymattw

Depends on the situation:

  • I would sometimes like to use the search in the pager, to double check if a diff contains or doesn't contain a word
  • I use it as part of a scripts/aliases (e.g. to check the diff before overwriting the branch), and would like a consistent workflow and muscle memory. Skipping the paging, might mean accidently confirm the next step, etc.
  • It's the standard Linux behaviour of most utilties, e.g. man and less. Those that have a different behaviour (e.g. systemd), allow that behaviour to be configured
  • And sometimes I would just want to display it on the console and not to use a pager

shaicoleman avatar Jan 28 '19 13:01 shaicoleman

I see, some of the use cases do make sense. Unfortunately the default options for less were (stolen) from git source code, changing that might break other users. A workaround for you is to reset the LESS environment variable (e.g. set to -R), either from cmd line or in your script, to override the behavior.

If the workaround is still annoying to you, feel free to send me a pull request. But I would prefer a logic to respect PAGER environment variable, rather than introducing new flags (auto/always/never).

ymattw avatar Jan 28 '19 19:01 ymattw

@shaicoleman FWIW, I too don't like the default --quit-if-one-screen behavior for the reasons you cited. As @ymattw suggests I get my preferred behavior by having a comprehensive LESS env var:

--HILITE-UNREAD --LONG-PROMPT --RAW-CONTROL-CHARS --chop-long-lines --ignore-case --jump-target=4 --no-init --quiet --search-skip-screen --shift=0 --squeeze-blank-lines --window=-2 --shift=.3 --prompt==%f\$ --prompt=M?f%f:*stdin*.  F %i/%m  .?ltL %lt-%lb/%L:?pt%pt\%:?btByte %bt:-...  C %c  ?Pt%Pt:?pt%pt:\?\?..\%?e EOF.\$

For the infrequent times that I don't want a pager I also don't want a side-by-side diffs so I just use git diff. It's not clear to me that a "don't pipe through a pager" option would be useful enough to justify even a few lines of additional code.

krader1961 avatar Jan 28 '19 19:01 krader1961

@ymattw, @krader1961, thanks, setting the LESS variable fixes it for my needs, it should probably be mentioned when running ydiff --help

shaicoleman avatar Jan 29 '19 00:01 shaicoleman

@ymattw I'm adding support for custom pagers to lazygit (examples) and I've got a use case for a --paging=never flag. I don't want ydiff using less at all, and I'm not aware of any way to make less unconditionally just render to stdout and exit. Happy to put up a PR

jesseduffield avatar Mar 03 '20 12:03 jesseduffield

Worth noting that git diff | ydiff -p cat actually still pipes to less, unlike what the docs say

jesseduffield avatar Mar 03 '20 12:03 jesseduffield

scratch that, if I download ydiff directly it works, but it looks like the pip and homebrew versions aren't up to date with master

jesseduffield avatar Mar 03 '20 12:03 jesseduffield

I ran into the same thing as @jesseduffield while trying to get ydiff hooked up to fzf via https://github.com/bigH/git-fuzzy. Any chance we can get a version bump?

mscottnelson avatar May 31 '20 17:05 mscottnelson

I'm having trouble making this feasible: pipe side-by-side and colorized output to another process (in this case, fzf preview). Mostly because there doesn't appear to be a way to bypass pipe-detection

mscottnelson avatar May 31 '20 19:05 mscottnelson

Hello, I am using ydiff as : ydiff -w 0 -s -p less, however the less page does not have colors. It appears has:

ESC[36mOnly in FolderA
ESC[0mESC[33mESC[0mESC[33mESC[0m

If I pass -p cat it works fine, but I would like to have one page per file. Is it possible to make less interpret the colors?

ghost avatar Sep 18 '21 16:09 ghost

Hello, I am using ydiff as : ydiff -w 0 -s -p less, however the less page does not have colors. It appears has:

ESC[36mOnly in FolderA
ESC[0mESC[33mESC[0mESC[33mESC[0m

If I pass -p cat it works fine, but I would like to have one page per file. Is it possible to make less interpret the colors?

This was solved with -p less -o '-R'. Sorry for the inconvenience!

ghost avatar Sep 18 '21 16:09 ghost

-p overrides the default pager (less) and also the default option for it, just drop -p less, it should work.

On Sat, Sep 18, 2021 at 6:44 PM mamanunu @.***> wrote:

Hello, I am using ydiff as : ydiff -w 0 -s -p less, however the less page does not have colors. It appears has:

ESC[36mOnly in FolderA ESC[0mESC[33mESC[0mESC[33mESC[0m

If I pass -p cat it works fine, but I would like to have one page per file. Is it possible to make less interpret the colors?

This was solved with -p less -o '-R'. Sorry for the inconvenience!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ymattw/ydiff/issues/82#issuecomment-922337961, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKXRD7KHPJYSPPOOWYEUQ3UCS6XRANCNFSM4GSXG7YA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ymattw avatar Sep 18 '21 16:09 ymattw