I want to define some alias iex="iex -S mix" only for one directory - this alias should work only when I cd'ed to this directory. Another requirement - this functionality should be placed inside this directory, hook file or something other, because I want to share this directory as a git repo.

How can I do that?


If you want iex to only work in one directory and never anywhere else try this:

alias iex='[ $(pwd) = /path/to/special/dir ] && iex –S mix'

If you want iex to work differently in other directories try it like this:

alias iex='[ $(pwd) = /path/to/special/dir ] && iex –S mix || iex'
  • This is an abuse of aliases. With this kind of thing, it is time to consider a function.
    – HalosGhost
    Sep 23 '16 at 1:58

My current development version of Bourne Shell (bosh) implements this feature since 6 jears. Check the man page:


and have a look at local persistent aliases - aliases local to a directory and persistent because they are kept in a file .locals of the related directory.

I am interested in feedback, in special whether there should also be .locals.#, where # is the user id of the user that is allowed to use them.

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