1

This question already has an answer here:

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?

marked as duplicate by muru, jimmij, Romeo Ninov, Wouter Verhelst, roaima Oct 22 '18 at 18:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

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
-2

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

http://schillix.sourceforge.net/man/man1/bosh.1.html

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.