bling / fzf.el

A front-end for fzf
GNU General Public License v3.0
369 stars 50 forks source link

FZF opens dired buffer instead of file when passing arguments through FZF_DEFAULT_COMMAND #118

Closed Doodler8888 closed 9 months ago

Doodler8888 commented 10 months ago

Hello,

I'm trying to configure the FZF package in Emacs and I'm encountering an issue when I attempt to pass arguments through the FZF_DEFAULT_COMMANDenvironment variable.

I have two functions: fzf-from-home which works as expected, and fzf-from-home-with-fd which uses fd with some arguments. Here are the definitions:

  (defun fzf-from-home-with-fd ()
    "Starts fzf from the user's home directory using fd to include hidden files and exclude certain directories."
    (interactive)
    (let ((process-environment (cons "FZF_DEFAULT_COMMAND=fd --type f --hidden --follow --exclude .git . ~"
                                    process-environment))
          (default-directory "~/"))
      (fzf-directory)))

  (defun fzf-from-home ()
    "Starts fzf from the user's home directory."
    (interactive)
    (let ((default-directory "~/"))
      (fzf-directory)))

When I use fzf-from-home, it correctly opens the file I choose. However, when I use fzf-from-home-with-fd, it opens a dired buffer instead. This happens regardless of whether I use fd or find.

I have tried escaping the file paths using sed, but the issue persists:

  (defun fzf-from-home-with-fd ()
    "Starts fzf from the user's home directory using fd to include hidden files and exclude certain directories."
    (interactive)
    (let ((process-environment (cons "FZF_DEFAULT_COMMAND=fd --type f --hidden --follow --exclude .git . ~ | sed -e 's/ /\\\\ /g'"
                                    process-environment))
          (default-directory "~/"))
      (fzf-directory)))

Emacs version: 29.1

Doodler8888 commented 9 months ago

it was my mistake:


(defun fzf-from-home-with-fd ()
    "Starts fzf from the user's home directory using fd to include hidden files and exclude certain directories."
    (interactive)
    (setenv "FZF_DEFAULT_COMMAND" "fd --type f --hidden --follow --exclude .git .")
    (let ((default-directory "~/"))
      (fzf-directory)))```