-
Create a new file called
.autoenv(this name is excluded from version control in.gitignore).
You can use it to automatically execute shell commands when entering folder. Add some commands to your.autoenvfile, like in the example below:# activate conda environment conda activate myenv # activate hydra tab completion for bash eval "$(python train.py -sc install=bash)"
(these commands will be executed whenever you're openning or switching terminal to folder containing
.autoenvfile) -
To setup this automation for bash, execute the following line (it will append your
.bashrcfile):echo "autoenv() { if [ -x .autoenv ]; then source .autoenv ; echo '.autoenv executed' ; fi } ; cd() { builtin cd \"\$@\" ; autoenv ; } ; autoenv" >> ~/.bashrc
-
Lastly add execution previliges to your
.autoenvfile:chmod +x .autoenv(for safety, only
.autoenvwith previligies will be executed)
Explanation
The mentioned line appends your .bashrc file with 2 commands:
autoenv() { if [ -x .autoenv ]; then source .autoenv ; echo '.autoenv executed' ; fi }- this declares theautoenv()function, which executes.autoenvfile if it exists in current work dir and has execution previligiescd() { builtin cd \"\$@\" ; autoenv ; } ; autoenv- this extends behaviour ofcdcommand, to make it executeautoenv()function each time you change folder in terminal or open new terminal