Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I defined an alias:

alias school="cd ~/School/3BaFys/"

to quickly go to the folder 3BaFys which contains all of the directories I need this year.

Is there a way to tell zsh that when I do:

$school Num<TAB>

this expands to

$school Numerieke\ Methoden

where Numerieke \Methoden is a sub directory of ~/School/3BaFys/

eg, tell the shell what school actually does and enabling it the be smart?

share|improve this question
up vote 4 down vote accepted


I just found this article describing how to do it.

Basically you rewrite your alias to a function, and then use some compctl magic on it.

This should solve your problem:

school() { cd ~/School/3BaFys/$@; }
compctl -/ -W ~/School/3BaFys school
share|improve this answer
Actually, this seems so nice I'll probably put something similar in my zsh config as well... – Martin Frost Nov 2 '11 at 13:59

Yes, but it might be more convenient to tackle the problem slightly differently.

setopt autocd

Type the command line $school to change to that directory. Type $school/Numerieke\ Methoden to change to that directory, and you'll have completion on the Numerieke Methoden part (and on school, too) out of the box. And you can write things like xpdf $school/foo.pdf to access files in that directory without changing to it.

If you don't like polluting your parameter space, you can use a named directory:

hash -d school=~/School/3BaFys/
ls ~school
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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