junegunn / fzf.vim

fzf :heart: vim
MIT License
9.52k stars 582 forks source link

Fzf.vim wants to use WSL even if bat.exe is available. #1457

Closed avysk closed 1 month ago

avysk commented 1 year ago

Hello, thanks for the great plugin! I miss something and would appreciate any pointers.

I run Windows 11, and I have native (Windows exe) fzf, bat, ag, rg. However, whenever fzf.vim wants to show a preview, it executes batcat in WSL. I was not able to inform fzf.vim that I have bat.exe without overriding fzf.vim's commands. Do I miss something?

junegunn commented 1 month ago

That's probably because of this code:

https://github.com/junegunn/fzf.vim/blob/a50c2640b9de23b10b3927873b519930cb8a7984/bin/preview.sh#L58-L63

So you have batcat, but prefer to use bat? Then I can change the code to use $BATNAME if it's defined.

diff --git a/bin/preview.sh b/bin/preview.sh
index 3c11dec..3c12dbd 100755
--- a/bin/preview.sh
+++ b/bin/preview.sh
@@ -56,10 +56,12 @@ if [ -z "$CENTER" ]; then
 fi

 # Sometimes bat is installed as batcat.
-if command -v batcat > /dev/null; then
-  BATNAME="batcat"
-elif command -v bat > /dev/null; then
-  BATNAME="bat"
+if [[ -z "$BATNAME" ]]; then
+  if command -v batcat > /dev/null; then
+    BATNAME="batcat"
+  elif command -v bat > /dev/null; then
+    BATNAME="bat"
+  fi
 fi

 if [ -z "$FZF_PREVIEW_COMMAND" ] && [ "${BATNAME:+x}" ]; then

And you set let $BATNAME = 'bat' in your configuration file.

junegunn commented 1 month ago

Let's name it $BATCAT to be more clear. i.e. let $BATCAT = 'bat'