Last active
October 26, 2020 13:30
-
-
Save jaredyam/b8e987664efeb98261247b215f1716be to your computer and use it in GitHub Desktop.
Wrap up the project environment activate/deactivate methods in the cd command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cd-with-auto-project-env.sh | |
| # | |
| # Wrap up the project environment activate/deactivate methods in the cd command. | |
| # | |
| # Custom | |
| # ------ | |
| # 1. env : environment directory contained in the project root. | |
| # 2. conda activate ./env : method to activate the target environment. | |
| # 3. conda deactivate : method to deactivate the current environment. | |
| # Prerequisite | |
| # ------------ | |
| # The system variable $PYTHONPATH should have been set (or unset) | |
| # when you're in (or out of) the project directory. | |
| # Recommend to use the `direnv` tool for this purpose. | |
| cd() { | |
| builtin cd "$1" | |
| if [ -n "$PYTHONPATH" ]; then | |
| conda activate "$PYTHONPATH"/env | |
| __conda_activated="True" | |
| elif [ -n "$__conda_activated" ] && [ -z "$PYTHONPATH" ]; then | |
| conda deactivate | |
| unset __conda_activated | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment