Gary
07/03/2025, 10:10 AMMarvin
07/03/2025, 10:10 AMMarvin
07/03/2025, 10:11 AM.bashrc
or .zshrc
:
bash
function cd() {
builtin cd "$@"
# Check for specific project directories and set profile
case $PWD in
*/project_a*)
prefect profile use p_a
;;
*/project_b*)
prefect profile use p_b
;;
esac
}
2. Using direnv (recommended):
This is a more robust solution that automatically loads/unloads environment variables when you enter/exit directories.
First, install direnv (varies by OS), then:
a. Create a .envrc
file in project A:
bash
export PREFECT_PROFILE=p_a
b. Create a .envrc
file in project B:
bash
export PREFECT_PROFILE=p_b
c. Allow the configurations:
bash
cd project_a
direnv allow
cd ../project_b
direnv allow
The direnv approach is more maintainable because:
- It's more explicit and easier to debug
- It works with any shell
- It automatically reverts when you leave the directory
- It can handle other environment variables too
Both approaches will automatically switch your Prefect profile when you change directories. The direnv solution is generally preferred as it's a standard tool for managing directory-specific environments.
For more information about Prefect profiles and how they work, you can check out the official documentation on settings and profiles.
Remember that only one profile can be active at a time, so these solutions will help you switch between them automatically as you move between projects.