Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Don't always page with --navigate option. #234

Closed
kevinhwang91 opened this issue Jul 4, 2020 · 11 comments
Closed

🚀 Don't always page with --navigate option. #234

kevinhwang91 opened this issue Jul 4, 2020 · 11 comments

Comments

@kevinhwang91
Copy link

When the output of git diff is shorter than the screen lines, delta always pages the output.
image

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Jul 4, 2020

Well, it doesn't always page the output; you can control this behavior with the options for less (assuming that less is configured as your pager), e.g.

LESS=F git diff

E/ or (which means the same as above)

LESS=--quit-if-one-screen git diff

@kevinhwang91
Copy link
Author

It doesn't work for me.

GIT_PAGER='delta --navigate' LESS=F git diff

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Jul 4, 2020

Whoops sorry... I overlooked you were referring to --navigate. My bad.

@dandavison
Copy link
Owner

dandavison commented Jul 4, 2020

Thanks @kevinhwang91 and @Kr1ss-XD, I noticed this also and was disappointed by it. I think that this is a problem with less, not with delta. Note that delta --navigate is implemented by delta starting a less process passing --pattern=<some regex>. When delta is in --navigate mode, it doesn't change anything about the way it usually invokes less, other than passing --pattern <regex> (and setting the LESSANSIENDCHARS env var to mK).

But see e.g. see https://superuser.com/questions/951405/less-with-f-option-and-pattern-matching, or experiment with piping input to less --pattern --quit-if-one-screen. It seems that less fills the screen with these lines if given short input and --pattern.

So, the question is -- can anyone come up with a cat myfile.txt | less --pattern ... invocation that behaves the way they would like? If not, then this might have to be solved in less, if that is possible. I don't know any sane way to implement delta --navigate other than via less --pattern.

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Jul 4, 2020

@dandavison not sure if you can use that, but

LESS=XE less --pattern=$pattern <short_file>

does exit from less if short_file fits into the screen.

E/ but it skips the text before the first occurence of $pattern...

@kevinhwang91
Copy link
Author

It seems that I shouldn't use --navigate option until this issue was solved. Honestly, I hate to fill the screen after invoking delta.

@dandavison You can close this issue if you want.

@kevinhwang91
Copy link
Author

#237 has discussed this issue.

@ronjouch
Copy link
Contributor

ronjouch commented Jul 13, 2020

This thread helped me realize what was wrong in my config, and causing --paging=auto to fail, printing these ~ characters and failing to not page in short diffs: I configure my less with LESS='-M +Gg', for less to display in its status bar a percentage of where I'm in the file. So, keeping this as-is because it's helpful when lessing a big file, e.g. a log, but overriding it with LESS=F in my diff alias.

Thanks for the discussion, everybody.

EDIT one more tweak: keep preserving my status bar with percentage (LESS='-M +Gg') when the diff is bigger than a screenful. Here's my updated d alias from my .gitconfig:

d = "!git status -s && if [ $(git --no-pager diff | wc -l) -gt $(tput lines) ]; then ENVVAR='THEVOID=yes'; else ENVVAR='LESS=F'; fi && echo && env $ENVVAR git diff"

@dandavison
Copy link
Owner

dandavison commented Jul 13, 2020

It seems that I shouldn't use --navigate option until this issue was solved

@kevinhwang91 I don't have a proper solution yet but one nice thing is that we can easily toggle navigate on/off like this:

git config --global delta.navigate true

I'm finding that makes it fairly convenient to activate when appropriate (e.g. for git log -p or a commit you know has many files & hunks). Of course, one could also create shell functions/aliases doing something similar.

@dandavison
Copy link
Owner

The latest release of delta allows navigate to be activated via an environment variable, e.g.:

DELTA_NAVIGATE=1 git diff

This is motivated by the fact that leaving navigate active all the time is problematic; please see the README section https://github.com/dandavison/delta#navigation-keybindings-for-large-diffs

@dandavison
Copy link
Owner

dandavison commented Feb 17, 2021

In addition to the DELTA_NAVIGATE env var, git -c ... can now be used with all delta options. I think this is an improvement in our abilities to configure delta on-the-fly. So here for example,

git -c delta.navigate=true log -p
git -c delta.navigate=false log -p

This requires delta 0.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants