PatrickF1 / fzf.fish

🔍🐟 Fzf plugin for Fish
MIT License
1.96k stars 78 forks source link

aliasing fd causes Search Directory to hang #281

Closed Susensio closed 1 year ago

Susensio commented 1 year ago

I have fd aliased to a less pager, like so:

function fd --wraps=fdfind --description 'alias fd=fdfind'
  if isatty stdout
    command fdfind --color always $argv | less
  else
    command fdfind $argv
  end
end

This is causing Directory Search to hang until all results have been found.

280 Fixes than by checking that unwrapped fd is called.

Susensio commented 1 year ago

The thing is I don't know why it hangs.

PatrickF1 commented 1 year ago

Hi Susensio, I wonder if it's possible fish functions don't support streaming in pipelines, so they block until they have received all the data? Anyway, I don't think this isn't a bug with fzf.fish

Susensio commented 1 year ago

Hi Patrick, I thought too that something must be wrong with buffering in fish functions. I know fd is sometimes installed as fdfind, I myself have that issue, thus the alias used. Anyway the hanging is undesirable and unavoidable without command.

Other problem that I've encountered is that if I alias with arguments fd to fd --color always for example, the plugin append twice the same parameter and fd fails.

I think it would be safer to use commanded binaries instead of maybe aliases. What do you think of using fd or fdfind? We could check which one is available and use it accordingly.

Let me know what you think and I can submit a PR that handles this edge case.

Susensio commented 1 year ago

As stated in https://github.com/fish-shell/fish-shell/issues/1396 it seems that piping from fish function (aliased fd) to fish function (_fzf_wrapper) is buffered. That's the problem. I think the easier workaround is to use command somehow.

PatrickF1 commented 1 year ago

Does Search Directory still hang if, instead of creating a wrapper function for fd, you use an alias?

PatrickF1 commented 1 year ago

Oh it probably does because fish aliases basically creates a function unlike other shells. Okay yeah, let's add command fd I'll update the docs to tell people to symlink instead of aliasing. However, I don't want to look for fdfind and use it if it's available because Search Directory is becoming monstrous and I despise maintaining it.

Susensio commented 1 year ago

I've submitted a PR #282 that solves the fd or fdfind binary problem without aliases. I think it's fairy simple and doesn't add much complexity.

The problem with #280 and symlink that you suggest is that it would be a breaking change and suddenly the extension will stop working for the people that use fish aliases