1

I have a function set up in ZSH to quickly navigate to a folder within my ~/Sites directory.

site() { cd ~/Sites/"$1"/website/; }

So if I type site clientsite it will cd into ~/Sites/clientsite/website/, nothing too complex going on here.

I am wondering how I get this to autocomplete based on the folders that I have inside ~/Sites/.

So when I type site cli[HIT TAB] it will autocomplete to site clientsite.

2
  • 1
    The alias seems unrelated to your actual question.
    – chepner
    Dec 22, 2015 at 14:49
  • Ah right your are. I have removed it from the question.
    – nickspiel
    Dec 22, 2015 at 20:24

1 Answer 1

5

In addition to the two lines you have:

alias sites='cd ~/Sites'
site() { cd ~/Sites/"$1"/website/; }

Add these two lines:

_site() { _files -W ~/Sites; }
compdef _site site

That should give you the tab completion you're looking for.

1
  • Brilliant! That is exactly what I was after!
    – nickspiel
    Dec 22, 2015 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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