I have a software project that I'm attempting to write zsh completions for. After installing a package that provided a number of pre-made completions, I found they were put here:


So I wrote my completion script, and threw it in there too. ...and was frustrated by failure. I've tried the following:

  1. Symlinking to the original script from the directory above.
  2. Putting a copy of the script directly into the directory above.
  3. Setting my login shell to zsh (instead of just switching to it from another shell)
  4. (Probably) all permutations of compinit and rehash.
  5. Dumbing-down my original script so that there's no way it could be wrong.
  6. Changing the contents of another script. The changes worked, so the directory is correct and zsh is detecting completions scripts there.

Here is the dumbed-down script:

#compdef aura

_arguments -s \
  '-V[Version!]' \

And the current contents of my .zshrc. I'm not normally a zsh user.

autoload -U compinit
zstyle ':completion:*' rehash true

Please and thank you for any insight you can give. What am I missing?

EDIT: Contents of /usr/share/zsh/site-functions is:

_ack _adb _android _attach _aura _baselayout _bpython _brew _bundle _cap _choc _coffee _cower _cpanm _debuild _dhcpcd _ditz _emulator _eselect _fab _gas _gcc-config _geany _gem _genlop _gentoolkit _gentoo_packages _git-flow _github _git-pulls _git-wtf _google _gradle _heroku _jmeter _jmeter-plugins _jonas _knife _language_codes _layman _lein _lunar _lunchy _manage.py _mosh _mvn _node _optirun _pacman _pactree _pear _perf _periscope _pgsql_utils _pip _pkcon _play _port _portage _portage_utils _pygmentize _redis-cli _rvm _sbt _scala _sdd _setup.py _showoff _smartmontools _srm _ssh-copy-id _subliminal _symfony _systemd _teamocil _thor _tmuxinator _vagrant _virtualbox _vnstat _vpnc _yaourt

  • Is the script called _aura? What does echo $_comps[aura] show? – Gilles Dec 29 '12 at 22:39
  • The script is called _aura, but echo $_comps[aura] returns an empty string. – Colin Woodbury Dec 29 '12 at 23:10
  • What is the value of fpath? What is the content of /usr/share/zsh/site-functions (which by the way is not the proper place to install your script, /usr/share is reserved for the package manager, you should put your scripts under /usr/local or your home directory)? Are there *.zwc files around? – Gilles Dec 29 '12 at 23:12
  • Thanks for helping. The contents of fpath are: /usr/share/zsh/site-functions and all directories under /usr/share/zsh/functions/. There were too many to type out. – Colin Woodbury Dec 29 '12 at 23:29
  • And it doesn't seem as if there are any .zwc files anywhere. I put the contents of /usr/share/zsh/site-functions in the original post. – Colin Woodbury Dec 29 '12 at 23:41

Here's what I think of that can go wrong.

The file containing the completion code must be in a directory listed in the fpath array. Ok. Note that you should not put your own files under /usr/share; zsh doesn't care, but your file could be deleted or overwritten by your operating system's package manager, and you're likely to forget to back it up, copy it to another machine, etc. You should put your own files under /usr/local if you want to make them available to all users on your system, and under your home directory if you just want them for your user. You can add a directory to fpath in your .zshrc (before calling compinit), e.g.

fpath=(~/lib/zsh $fpath)

The first line of the file must be #compdef followed by a space followed by one or more command names separated by spaces. Check that there aren't any stray characters there, in particular the file must have unix line endings (LF), not Windows line endings (CRLF — the stray CR might cause the command not to be picked up).

The compinit function creates a cache file the first time it runs, so as to be faster next time. This file is called ~/.zcompdump. It contains the association between command names and completion functions (e.g. aura _aura), not the code of the functions. You may need to regenerate it sometimes. In particular, if you change the #compdef line in an existing file, compinit won't re-read the file. As long as you don't pass -C to compinit, it will pick up new files, but you must get the #compdef line right before the next time you start zsh. If you didn't, delete the cache file (rm ~/.zcompdump) and start zsh (or more precisely run compinit) again.

  • Zapped my old .zcompdump and now it works! Thanks a ton @Gilles. – Colin Woodbury Dec 30 '12 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.