junegunn / fzf-git.sh

bash and zsh key bindings for Git objects, powered by fzf
612 stars 53 forks source link

Add colorless mode #44

Closed sobolevn closed 4 months ago

sobolevn commented 4 months ago

Hi! Great stuff.

Some people are not that great with colors. Can a mode without git colors be added please? I am specifically talking about things like:

I would propose to add a setting called FZF_GIT_NO_COLOR=true to disable these colors :) Would you accept a PR like this?

junegunn commented 4 months ago

Have you considered adding --no-color to your $FZF_DEFAULT_OPTS? It will suppress all colors from fzf.

sobolevn commented 4 months ago

Some colors are fine. But, the ones I've linked are too much :)

junegunn commented 4 months ago

Okay then, what do you think about changing --color=always to --color=${FZF_GIT_COLOR:-always}? So you can export FZF_GIT_COLOR=auto.

sobolevn commented 4 months ago

Looks good to me! πŸ‘

junegunn commented 4 months ago

I've given it some thought and I think we should follow https://no-color.org/.

junegunn commented 4 months ago

Or maybe not? If fzf starts respecting $NO_COLOR, you'll lose all colors.

sobolevn commented 4 months ago

I think that supporting NO_COLOR is always a good thing. But, this is a global switch. I think that adding FZF_GIT_COLOR is also a good idea. This way:

sobolevn commented 4 months ago

Btw, _fzf_git_bat_options="--style='${BAT_STYLE:-full}' --color=$(__fzf_git_color) --pager=never" this should be a different setting 100%

Disabling git colors is not the same as code highlight, which is very needed.

junegunn commented 4 months ago

How about this?

diff --git a/fzf-git.sh b/fzf-git.sh
index bef581d..27d01f0 100644
--- a/fzf-git.sh
+++ b/fzf-git.sh
@@ -27,11 +27,16 @@ __fzf_git_color() {
   if [[ -n $NO_COLOR ]]; then
     echo never
   else
-    echo always
+    echo ${FZF_GIT_COLOR:-always}
   fi
 }

 __fzf_git_cat() {
+  if [[ -n $FZF_GIT_CAT ]]; then
+    echo $FZF_GIT_CAT
+    return
+  fi
+
   # Sometimes bat is installed as batcat
   _fzf_git_bat_options="--style='${BAT_STYLE:-full}' --color=$(__fzf_git_color) --pager=never"
   if command -v batcat > /dev/null; then
sobolevn commented 4 months ago

amazing! πŸš€

junegunn commented 4 months ago

That would allow something like this:

export FZF_GIT_COLOR=never
export FZF_GIT_CAT='bat --style=numbers --color=always'

But the problem with this is that, the preview window of CTRL-G-F has colors because it's using bat, but the preview windows of the other bindings, such as CTRL-G-H, do not.

So maybe we need another variable for controlling the colors in the preview window.

junegunn commented 4 months ago

bd8ac4ba4c9d7d12b34f7fa2b0d334f50cdb5254

sobolevn commented 4 months ago

SO MUCH BETTER!

Before:

Π‘Π½ΠΈΠΌΠΎΠΊ экрана 2024-05-14 Π² 16 01 38

After:

Π‘Π½ΠΈΠΌΠΎΠΊ экрана 2024-05-14 Π² 16 01 50

Thanks a lot for the quick reply and quick fix! fzf is amazing :) I am integrating it into my workflow right now https://github.com/sobolevn/dotfiles?tab=readme-ov-file#fzf-goodies

sobolevn commented 4 months ago

And with export FZF_GIT_PREVIEW_COLOR=always and FZF_GIT_COLOR=never:

Π‘Π½ΠΈΠΌΠΎΠΊ экрана 2024-05-14 Π² 16 05 54

πŸŽ‰