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

🐛 Can't disable line numbering from command line #307

Closed
HaleTom opened this issue Sep 1, 2020 · 9 comments · Fixed by #495
Closed

🐛 Can't disable line numbering from command line #307

HaleTom opened this issue Sep 1, 2020 · 9 comments · Fixed by #495

Comments

@HaleTom
Copy link

HaleTom commented Sep 1, 2020

If I run:

git diff | delta --line-numbers=false | cat

I see line numbers.

How do I disable line numbers from the command line?

I tried --no-line-numbers, but no joy. It would be great to be able to disable any boolean with --no-*, to override something that had been previously enabled (eg by a script or bash alias)

@dandavison
Copy link
Owner

Hi @HaleTom, thanks for this. I agree it would be nice if this were more convenient. I think the best that's available right now is:

  1. git config --global delta.line-numbers false; git diff
    Not perfect but I've been finding this approach quite useful. Of course one can go further in this direction with custom shell aliases / wrapper functions.

  2. delta --no-gitconfig
    But then you have to build back up the options you do require

A couple of tangential thoughts:

Sometimes I wonder if it might have been better not to use boolean flags at all in delta and only use flags with explicit values, especially seeing as delta is mostly not used directly at the command line. However, I don't think there's a path there that retains backwards compatibility.

Is adding --no-* negating versions automatically something that one could hope that Rust's clap (and hence structOpt) package could do automatically? I don't think it does.

@dandavison
Copy link
Owner

Ref clap-rs/clap#815 ("Add support for automatic negation flags")

@dandavison
Copy link
Owner

The current plan for addressing this is #340 (comment) (and see #446).

@dandavison
Copy link
Owner

@HaleTom is the following a workaround for you?

[delta]
    features = line-numbers

[delta "no-line-numbers"]
    line-numbers = false

Now by default delta will have line-numbers and they can be disabled with delta --features=no-line-numbers, or DELTA_FEATURES=no-line-numbers git show etc. There's similar discussion at #492 (comment) and dandavison/magit-delta#13 (comment).

dandavison added a commit that referenced this issue Jan 8, 2021
When git is invoked as `git -c aaa.bbb=ccc -c ddd.eee=fff` then git
sets the env var GIT_CONFIG_PARAMETERS containing the changed config
entries, so that child processes can honor them.

libgit2 doesn't yet honor the env var: see
libgit2/libgit2#3854.

Fixes #493
Fixes #307
Ref dandavison/magit-delta#13
dandavison added a commit that referenced this issue Jan 8, 2021
When git is invoked as `git -c aaa.bbb=ccc -c ddd.eee=fff` then git
sets the env var GIT_CONFIG_PARAMETERS containing the changed config
entries, so that child processes can honor them.

libgit2 doesn't yet honor the env var: see
libgit2/libgit2#3854.

Fixes #493
Fixes #307
Ref dandavison/magit-delta#13
dandavison added a commit that referenced this issue Jan 8, 2021
When git is invoked as `git -c aaa.bbb=ccc -c ddd.eee=fff` then git
sets the env var GIT_CONFIG_PARAMETERS containing the changed config
entries, so that child processes can honor them.

libgit2 doesn't yet honor the env var: see
libgit2/libgit2#3854.

Fixes #493
Fixes #307
Ref dandavison/magit-delta#13
dandavison added a commit that referenced this issue Jan 8, 2021
When git is invoked as `git -c aaa.bbb=ccc -c ddd.eee=fff` then git
sets the env var GIT_CONFIG_PARAMETERS containing the changed config
entries, so that child processes can honor them.

libgit2 doesn't yet honor the env var: see
libgit2/libgit2#3854.

Fixes #493
Fixes #307
Ref dandavison/magit-delta#13
@dandavison
Copy link
Owner

In the master branch we can now do git -c delta.line-numbers=false (see #493).

So I think that's the most convenient way to do it for the case of using delta with git. It should also be possible to disable it on the delta command line somehow, but perhaps that's less of a priority since we can do it conveniently in the git case, and we have the features workaround #307 (comment) otherwise.

@Atemu
Copy link

Atemu commented Jun 25, 2022

@dandavison I'm using your magit plugin and want it to display line numbers when called from command line git but not when called from magit.
In order to achieve that, line-numbers needs to be in the git config and magit needs a --no-line-numbers flag to override it.

@dandavison
Copy link
Owner

Hi @Atemu, two thoughts:

  1. If you only need a few options set in magit-delta, then you could make it be completely independent of your git config using --no-gitconfig. This is what I do:
  (add-to-list 'magit-delta-delta-args "--no-gitconfig")
  (add-to-list 'magit-delta-delta-args "--light")
  1. Otherwise, I think it should be possible to do what you want with a delta "feature" for use by magit-delta. This might take a bit of playing around, but I just had a go and the following seems to work:
[delta]
   features = not-magit-delta

[delta "not-magit-delta"]
   line-numbers = true

[delta "magit-delta"]
    line-numbers = false
  (setq magit-delta-delta-args (append magit-delta-delta-args '("--features" "magit-delta")))

@dandavison
Copy link
Owner

This doesn't help with disabling something set in git config, but in case anyone comes across this issue searching for how to conveniently enable something like line-numbers or side-by-side, then IMO the best way is the DELTA_FEATURES environment variable, with its special and very useful + prefix (thanks to @bew: #848 (comment)):

on:

export DELTA_FEATURES=+line-numbers

off:

export DELTA_FEATURES=+

@God-damnit-all
Copy link

Using GIT_CONFIG_PARAMETERS isn't a bad solution, but you can't use in combination with --no-gitconfig

Honestly, I don't see why --no-line-numbers can't just be a CLI option.

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

Successfully merging a pull request may close this issue.

4 participants