I am a fan of Direnv, however when I wanted to add custom project specific aliases and other helper functions etc, I soon came across https://github.com/direnv/direnv/issues/73. There are some good workarounds proposed to address this issue, but none of them felt clean to me. There also exist alternatives that offer similar solutions but why waste time if it can be better spent building something quickly yourself. So I considered rolling out something basic on my own. This is what it looks like :
The idea here is fairly straight forward, I can add 2 special files to a project directory,
.zshrc.exit and these will get loaded once I enter / leave the directory in zsh shell respectively. This allows me to add project specific custom functions / aliases etc within the
.zshrc.enter and clean them up in
.zshrc.exit so when I move out from the project directory they are no more cluttering my global configuration.
Tip: I recommend adding these 2 files to your global gitignore file so you don’t have to worry about ignoring locally in different projects if you use git a lot.
NOTE: This is a very basic version and does not have security measures such as whitelisting directories to ensure no malicious code gets sourced accidentally. So use it at your own risk.