Zend certified PHP/Magento developer

zsh autocompletion of my own function

I’m trying to write a shortcut for a frequently visited directory so that I can eliminatecd (I know, I know, but I’m lazy).

So I wrote a function in my .zshrc that does this:

progs () {
  if [[ -z $1 ]]; then
    cd /Volumes/data/progs
  else
    cd /Volumes/data/progs/$1
  fi
}

The intention being that if I jus type progs I go to the top level directory, but if I type progs foo it cd’s to the '.../progs/foo' directory. However, I’d like to have the autocompletion system allow me to do a after progs to simulate the behavior of cd.

I’ve written a helper function:

function _progs() {
  _alternative "dirs:user directory:($(ls /Volumes/data/progs/$1))"
}

and then used:

compdef _progs progs

That worked fine until I created directories with spaces in them. Now, it list every word as the option not every directory.

How do I tell the autocomplete subsystem to list all files/directories as if I was completing “cd”?

BTW I do know about cdpath and that’s fine, but I still have to type cd progs . I also tried the _files builtin instead of running ls in my helper function, but I can’t get the _files builtin to accept a different directory.