unixorn / fzf-zsh-plugin

ZSH plugin to enable fzf searches of a lot more stuff - docker, tmux, homebrew and more.
Apache License 2.0
303 stars 27 forks source link

Avoid automatic installation when already installed #109

Open Alveel opened 2 months ago

Alveel commented 2 months ago

It seems this plugin always wants to install fzf to its own path, even though one might already have it installed through another package manager.

Is there a way to disable installation of fzf, and having the plugin detect it in PATH?

hendrikbursian commented 1 month ago

I tried getting behind this as I had the same issue.

What i found is that the _has_fzf function in the condition here https://github.com/unixorn/fzf-zsh-plugin/pull/98/files#diff-f8b5fe7a56eebe212a2d1abddb46078b6d2a569f9f9cf3ea3562d68314cdc37bR50

doesn't work correctly.

The following are my outputs (when inlining the _has_fzf function)

▶ which fzf                  
/etc/profiles/per-user/hendrik/bin/fzf

▶ [[ ! $(which "fzf" > /dev/null 2>&1) ]] && echo "fzf not installed" 
fzf not installed

▶ [[ ! $(which "fzf_not_valid" > /dev/null 2>&1) ]] && echo "fzf not installed"
fzf not installed

When instead I use the command shell builtin it works as expected.

▶ command -v fzf
/etc/profiles/per-user/hendrik/bin/fzf

▶ command -v fzf >/dev/null 2>&1 && echo "fzf installed"                   
fzf installed

▶ command -v fzf_not_valid >/dev/null 2>&1 && echo "fzf installed"
[ no output here ]

I'm not a shell wizard so I can't tell if the "which" expression can be fixed without parsing its output. If nothing speaks against it I'd use the command builtin like this:

▶ function _fzf_has() {                       
  command -v "$@" > /dev/null 2>&1
}

▶ if ! _fzf_has fzf; then echo "installing fzf"; fi
[ no output here ]       

▶ if ! _fzf_has fzf_not_valid; then echo "installing fzf"; fi
installing fzf

I'm happy to provide a PR if you approve.

Kind regards