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

Completions by brew installed packages are missing #2103

Open
onc opened this issue Jan 9, 2025 · 7 comments
Open

Completions by brew installed packages are missing #2103

onc opened this issue Jan 9, 2025 · 7 comments

Comments

@onc
Copy link

onc commented Jan 9, 2025

Description

First, thank you for this project. I was using oh-my-zsh for years and just recently switched to prezto and oh boy, it feels so good! Never going back!

While configuring my system, I noticed that completions from homebrew installed packages are not working. After some investigations, I noticed that the homebrew fpath is missing in the fpath build by prezto. In my case this would be /opt/homebrew/share/zsh/site-functions.

I can achieve my desired behavior by doing the following:

# add to the end, so the zsh-completion some first and completions 
# for e.g. git are used from there instead of from the homebrew directory
fpath+=$(brew --prefix)/share/zsh/site-functions
compinit -i -d ...

Expected behavior

The homebrew completions path should added to fpath.

Actual behavior

The path is missing in fpath.

Steps to Reproduce

  1. type brew hit <TAB>

Versions

  • Prezto commit: 427268c
  • ZSH version: zsh 5.9 (arm64-apple-darwin24.0)
  • OS information: macOS 15.12
@indrajitr
Copy link
Collaborator

Hi @onc, this should have worked OOTB. Could you please verify if the path $(brew --prefix)/share/zsh/site-functions is owned by the logged in user?

@onc
Copy link
Author

onc commented Jan 16, 2025

Image

@indrajitr
Copy link
Collaborator

Hi @onc, I see what's happening.

Almost certainly you are using macOS bundled zsh (/bin/zsh) instead of Homebrew provided zsh ($(brew --prefix)/bin/zsh) - you can verify that by checking your $SHELL.

Usually, default site-fndir is configured at build time. You can see homebrew build spec here, for example.

Historically, macOS zsh used to be quite outdated, and using Homebrewed zsh was the norm. But now that they diverge much less, macOS bundled zsh if fine too. So adding in site-fndir might be a useful addition.

You can continue have fpath added in manually for now, but I'll see how it can be added in a suitable place by default (even when the user is using macOS bundled zsh instead of homebrewed one).

@onc
Copy link
Author

onc commented Jan 21, 2025

Yes, you are right. I'm using the macOS bundled version of zsh.

Thank you for your help.

@apfohl
Copy link

apfohl commented Jan 24, 2025

@onc I'm wondering what is wrong on my side. I added

fpath=(
  /opt/homebrew/share/zsh/site-functions
  $fpath
)

to my .zprofile. Now I have the path available when I print echo $fpath. But the completions for the e.g. brew command are not happening. I tried your compinit -i -d in my .zshrc but that does nothing besides huge loading time when opening a new shell.

My /opt/homebrew/share/zsh/site-functions is owned by a different user though brew, because I have two persons using this machine. And opted for a dedicated brew user for manage that. Not sure if that makes a problem???

I'm also on the same macOS default ZSH and same operation system (M1 Pro).

Any ideas, or maybe you could be more explicit?

thanks.

@apfohl
Copy link

apfohl commented Jan 24, 2025

@onc I'm wondering what is wrong on my side. I added

fpath=(
/opt/homebrew/share/zsh/site-functions
$fpath
)
to my .zprofile. Now I have the path available when I print echo $fpath. But the completions for the e.g. brew command are not happening. I tried your compinit -i -d in my .zshrc but that does nothing besides huge loading time when opening a new shell.

My /opt/homebrew/share/zsh/site-functions is owned by a different user though brew, because I have two persons using this machine. And opted for a dedicated brew user for manage that. Not sure if that makes a problem???

I'm also on the same macOS default ZSH and same operation system (M1 Pro).

Any ideas, or maybe you could be more explicit?

thanks.

UPDATE: It is indeed the different user... hmm. No idea, how to get this working....

compinit -u does the trick...

@onc
Copy link
Author

onc commented Jan 29, 2025

TLDR: add it like this to you ~/.zshrc, at least that is was working for me atm. It need to be before sourcing init.zsh.

# Add homebrew-installed package completions to fpath
if command -v brew > /dev/null; then
    fpath+=$(brew --prefix)/share/zsh/site-functions
fi

# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.dotfiles/prezto/init.zsh" ]]; then
  source "${ZDOTDIR:-$HOME}/.dotfiles/prezto/init.zsh"
fi

I'm not sure if I can help you here, I'm not an expert myself, but here is what I understand:

On you system, every path that is fpath is searched for completion-files. However, to make this faster, a cache file is created where all those completions are cached in one place rather than searching all those paths every time you ask for a completion.

This cache file is build using compinit. By default (when just running compinit) this cache file is build to ~/.zcompdump.

However, prezto does not use this location, but rather ~/.cache/prezto/zcompdump, therefore if you would call compinit yourself, you would need to call compinit -i -d ~/.cache/prezto/zcompdump instead. If this cache file is not there, it takes some time to build it. This is the huge loading time you experienced.

Also, by default, the zcompdump in your home-folder seems to be prefered over the one in ~/.cache, at least that is the case for me. So take if there is a file in your home-folder.

prezto will rebuild the cache every 20 hours (see here). And does some other magic. So rather than calling compinit myself, I just add it to fpath and let prezto do the rest.

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

No branches or pull requests

3 participants