2

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?

8
  • Would you be ok if it was a function instead? Commented Sep 22, 2016 at 9:34
  • And it should only work in one specific directory -- not any subdirectory? Commented Sep 22, 2016 at 9:49
  • Similar: unix.stackexchange.com/q/21363/117549 Commented Sep 22, 2016 at 9:59
  • Yes, only in one specific directory Commented Sep 22, 2016 at 10:14
  • Any shell or specific to one or more? Commented Sep 22, 2016 at 10:24

2 Answers 2

7

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'
1
  • This is an abuse of aliases. With this kind of thing, it is time to consider a function. Commented Sep 23, 2016 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.