Directory based environment variable scope - how to implement?

Igor Gatis picture Igor Gatis · May 1, 2011 · Viewed 10.4k times · Source

I have a set of tools which I need to pass parameters depending on the project I'm working on. I'd like to be able to automatically set a couple of environment variables based on the current directory. So when I switched between directories, my commonly used env vars would also change. Example:

Let's current directory is foo, thus if I do:

~/foo$ ./myscript --var1=$VAR1

VAR1 would have some foo based value.

Then, let's say I switched to bar directory. If I do:

~/bar$ ./myscript --var1=$VAR1

VAR1 should now have some bar based value.

Is that possible? How?

Answer

Dan D. picture Dan D. · May 1, 2011

the ondir program lets you specify actions to run when you enter and leave directories in a terminal