Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid automatic installation when already installed #109

Open
Alveel opened this issue Jul 19, 2024 · 1 comment
Open

Avoid automatic installation when already installed #109

Alveel opened this issue Jul 19, 2024 · 1 comment

Comments

@Alveel
Copy link

Alveel commented Jul 19, 2024

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?

unixorn added a commit that referenced this issue Jul 20, 2024
Add more debugging output to track down why we're getting reports
like #109 that the
plugin is installing `fzf` when it's already installed.

Signed-off-by: Joe Block <[email protected]>
@hendrikbursian
Copy link

hendrikbursian commented Aug 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants