forgit icon indicating copy to clipboard operation
forgit copied to clipboard

Add FORGIT_STASH_SHOW_PREVIEW_GIT_OPTS

Open ccoVeille opened this issue 1 year ago • 14 comments

Check list

  • [X] I have performed a self-review of my code
  • [ ] I have commented my code in hard-to-understand areas
  • [X] I have made corresponding changes to the documentation

Description

FORGIT_STASH_SHOW_PREVIEW_GIT_OPTS variable can be used to tune the rendering of a stash preview.

The following example allows listing the content of the stash before opening it.

FORGIT_STASH_SHOW_PREVIEW_GIT_OPTS="--patch-with-stat --stat-count=10"

Type of change

  • [ ] Bug fix
  • [X] New feature
  • [ ] Refactor
  • [ ] Breaking change
  • [ ] Documentation change

Test environment

  • Shell
    • [ ] bash
    • [ ] zsh
    • [X] fish
  • OS
    • [X] Linux
    • [ ] Mac OS X
    • [ ] Windows
    • [ ] Others:

ccoVeille avatar Apr 21 '24 14:04 ccoVeille

Thanks for your contribution @ccoVeille! Just some minor changes to do here. The code itself works fine for me and I find the ability of having the diff stat on top of the preview very neat. The example you provided will go straight to my dotfiles once this is merged 😉

Do you think, l I should add it to the documentation the same way FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS is explained ?

FORGIT_STASH_SHOW_PREVIEW_GIT_OPTS="--patch-with-stat --stat-count=10"

otherwise you can merge as this

ccoVeille avatar Apr 22 '24 21:04 ccoVeille

Do you think, l I should add it to the documentation the same way FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS is explained ?

Yes, that sounds useful :+1:

sandr01d avatar Apr 23 '24 21:04 sandr01d

@sandr01d pushed back with the changes in README.md

ccoVeille avatar Apr 24 '24 09:04 ccoVeille

Please relaunch the CI as it looks like a false positive due to apt

ccoVeille avatar Apr 24 '24 09:04 ccoVeille

I would suggest to wait for #391 before merging this (see my comment there).

carlfriedrich avatar Apr 24 '24 18:04 carlfriedrich

@sandr01d @ccoVeille For your information (because that seems to be similar to what you want to achieve here): you can override preview functions by defining your own and then include it in the according FORGIT_*_FZF_OPTS variable.

I am using this by defining a custom preview function for forgit logs and including that in my FORGIT_STASH_FZF_OPTS variable. It includes the diff stat in a dimmed representation, see a screenshot here:

grafik

This works already without introducing new variables, so might this eventually be an alternative way to go for you?

carlfriedrich avatar Apr 24 '24 18:04 carlfriedrich

~~My issue is that I cannot achieve what I want with the _FZF variables.~~

I don't want to affect the git command that is launched of the left, but the git command that are displayed on the right, the preview.

~~Right now, there is no way to do it.~~

Edited: I will have a look

ccoVeille avatar Apr 24 '24 18:04 ccoVeille

@sandr01d @ccoVeille For your information (because that seems to be similar to what you want to achieve here): you can override preview functions by defining your own and then include it in the according FORGIT_*_FZF_OPTS variable.

I am using this by defining a custom preview function for forgit logs and including that in my FORGIT_STASH_FZF_OPTS variable. It includes the diff stat in a dimmed representation, see a screenshot here:

grafik

This works already without introducing new variables, so might this eventually be an alternative way to go for you?

I find your solution too complex. I mean you reimplemented somehow the internals of forgit.

It's OK for an advanced shell user, but for a random dev who want to add a parameter to a command. Your code works, someone could copy paste it, but I don't think they would be able to maintain it.

ccoVeille avatar Apr 24 '24 19:04 ccoVeille

I don't want to affect the git command that is launched of the left, but the git command that are displayed on the right, the preview.

@ccoVeille Yes, I got that. Take a look at the links in my previous comment, those point to my dotfiles where I configure forgit similarly to what (I think) you want to achieve here. It works with the current forgit code base.

The point to understand is: instead of configuring the preview function, I replace it with my own (using fzf's --preview option). This gives you full freedom over any forgit preview, without having to add more variables to the forgit code.

carlfriedrich avatar Apr 24 '24 19:04 carlfriedrich

@ccoVeille Ah sorry, our comments overlapped. I agree that it's not a simple solution for everyone. However, maybe we could add an examples section to the README for use cases like this? Might be better than introducing more variables for things that already can be configured. Not sure about that myself, yet, though.

Curious to hear opinions from @wfxr @sandr01d @cjappl.

carlfriedrich avatar Apr 24 '24 19:04 carlfriedrich

Thanks for the insights @carlfriedrich. While the solution you provided is certainly an interesting way to solve this, I think replacing preview functions with injected code goes beyond configuration since it requires familiarity with the inner workings of forgit – at least to a certain extend. I think adding environment variables to handle this would simplify the process of customizing the preview quite a bit (while of course adding complexity to the project). I lean more towards adding such variables if we can manage to reduce boiler plate to a minimum. I agree that the changes from this PR and those proposed in #391 should go into a single PR.

sandr01d avatar Apr 25 '24 20:04 sandr01d

OK for me.

ccoVeille avatar Apr 25 '24 23:04 ccoVeille

For records, I don't think that I'll be able to work on it in the next days.

ccoVeille avatar Apr 25 '24 23:04 ccoVeille

For records, I don't think that I'll be able to work on it in the next days.

For records, I'm still alive, but we got a new kid, so well, I'm pretty busy :smile: for now

ccoVeille avatar May 27 '24 12:05 ccoVeille

Replaced by

  • #396

ccoVeille avatar Jul 17 '24 16:07 ccoVeille