Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop your shell from forgetting your directory context when you switch projects
🧩 The Challenge
You know that feeling when you’re juggling three different Git repos and keep landing in the wrong one after opening a new tab? I’ve burned so much time working on a config file only to realize I was editing the version in my staging directory instead of prod.
💡 The Fix
Use a shell function to auto-run a local directory config file whenever you cd into a specific project folder. It keeps your environment variables and aliases scoped strictly to where you are actually working.
chpwd() {
if [ -f .envrc ]; then
source .envrc
fi
}
⚙️ Why It Works
Adding this hook to your shell tells the terminal to check for a project-specific script every single time you change directories. It effectively creates a per-directory sandbox for your environment.
🚀 Pro-Tip: Toss an alias in that .envrc to override your global git user email for that specific client repo.
Linux Tips & Tricks | © ngelinux.com | 7/29/2026
