I have written a script for internal use in my job (it's not of much use to anyone outside of my work). I've got a decent zsh
completion script for it now which works great. I'd like to add an --install-zsh-completions
flag to my script, which sets up completions automatically.
I see that there are a variety of different ways that zsh
can be set up, depending on whether you use oh-my-zsh, prezto or your own configuration. (For example, in oh-my-zsh
, you can put completion scripts in ~/.oh-my-zsh/completions
and they are loaded.)
Is there a standard place or way in zsh
to install custom completion functions, so that they work for all users, regardless of their zsh
config? (For example, should I just modify the .zshrc
file and add to the fpath
? )
Is there a standard place or way in zsh to install zsh custom completion scripts?
Yes, there is: Create a symlink in /usr/local/share/zsh/site-functions
that points to your completion function. This dir is by default in every user's $fpath
. So, when they (or whatever framework they're using) calls compinit
, it will be picked up automatically.
Alternatively, if you cannot or do not want to write to that dir, you can tell the user to add the following to their .zshrc file:
fpath=(
/path/to/dir/containing/your/completion/functions
$fpath
)
For more info about installing Zsh completions, see my answer here.