-
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.autoenv
file, 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
.autoenv
file) -
To setup this automation for bash, execute the following line (it will append your
.bashrc
file):echo "autoenv() { if [ -x .autoenv ]; then source .autoenv ; echo '.autoenv executed' ; fi } ; cd() { builtin cd \"\$@\" ; autoenv ; } ; autoenv" >> ~/.bashrc
-
Lastly add execution previliges to your
.autoenv
file:chmod +x .autoenv
(for safety, only
.autoenv
with 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.autoenv
file if it exists in current work dir and has execution previligiescd() { builtin cd \"\$@\" ; autoenv ; } ; autoenv
- this extends behaviour ofcd
command, to make it executeautoenv()
function each time you change folder in terminal or open new terminal