r/zsh • • 13d ago

Help Understand where the fpath variable is set during initialisation

I'm trying to understand where the fpath variable is set during my zsh initialisation phase.

From what I understood the sequence is: zshenv -> zprofile -> zshrc -> zlogin (inside /etc/zsh/), and after that the .zshrc file inside my home directory.

Only two files in the /etc directory have command, zshenv and zshrc, but not set of fpath is present in both of them. zshenv set the PATH variable and zshrc has several lines (they should be the default ones because I never modified this file). In this file anyway an "autoload -U compinit" command is present and I think the fpath should be already set at this point.

The .zshrc file in my home directory has only three lines (HISTFILE, HISTSIZE and SAVEHIST)

Now, after that, I suppose the "echo $fpath" command should be return empty, but in reality it's full of directories pointing to /usr/share/zsh/<...>

What other files can be responsible for the setting of fpath (or in general what do I have to see)?

NOTE: my distro didn't ship with zsh pre-installed. I added ii in a second time by apt install

2 Upvotes

6 comments sorted by

3

u/jjangg96 13d ago

fpath isn't set by any startup file. zsh has a default value compiled in, so it's already populated before zshenv even runs. that's why it's never empty.

you can see it with zsh -f -c 'print -l $fpath'. -f skips all the rc files, including the ones in /etc/zsh, and you still get the same directories. compinit just reads fpath to find completion functions, it doesn't set it. anything beyond that default came from a file or plugin appending to it.

1

u/Ryan_Arr 13d ago

Full list and order of startup files: https://zsh.sourceforge.io/Guide/zshguide02.html (scroll down to section 2.2)

Add echo $fpath to your ~/.zshenv, if the offending entries are printed go up the list and see what happens if you put this line in /etc/zshenv instead. If not, go down the list instead.

I'd bet you're getting these from something in /etc, probably /etc/zshrc. If you want, you can disable the global zshrc and zprofile by adding setopt NO_GLOBAL_RCS to your ~/.zshenv.

1

u/AnlgDgtlInterface 13d ago

Completions are likely a point of blame.

0

u/a_alberti 13d ago

I thought any plugin and any of these files zshenv -> zprofile -> zshrc -> zlogin could in principle extend fpath.

If a package provider distributes a collection of completions, this will probably append its directory to the fpath. And plugins are typically loaded in .zshrc. The only place where it makes no sense to have fpath is zshenv and probably zprofile too, because fpath is for completions, i.e., for interactive shells. zshenv is always loaded, so it makes to me no sense to define there fpath.

I use zinit https://github.com/zdharma-continuum/zinit and it installs everything under a common fpath. So you will not get many entries in fpath but I can image other package manager make huge number of entries there?

0

u/Suddenspike 13d ago

I'm not sure, but looks like there are no plugin loaded inside /etc/zsh/zshrc

0

u/ultiweb 13d ago

zlogin only with login shells.