3

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:

/usr/share/zsh/site-functions

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!]' \
  '-h[Helpppp]'

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

autoload -U compinit
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

5
  • Is the script called _aura? What does echo $_comps[aura] show? Dec 29, 2012 at 22:39
  • The script is called _aura, but echo $_comps[aura] returns an empty string. Dec 29, 2012 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? Dec 29, 2012 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. Dec 29, 2012 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. Dec 29, 2012 at 23:41

1 Answer 1

1

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.

1
  • Zapped my old .zcompdump and now it works! Thanks a ton @Gilles. Dec 30, 2012 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .