(I'm using anaconda on a MacBook)
By default conda adds the environment info to the comand prompt as follows:
$ source activate my_env
(my_env) $ source deactivate
$
This can be switched off and on using
conda config --set changeps1 (true|false)
Since my terminal prompt is already customised I'd like to add the env info in a different way, but don't know how to exactly.
Right now I'm using the two commands sac
and dac
in my .bash_profile file to activate and deactivate envs and therefore did this amateurish attempt adding env_var
:
env_var=""
#activate env (default env = my_env)
sac() {
if [ -z $1 ];
then
ENV="my_env"
else
ENV="${1}"
fi
source activate ${ENV}
env_var="${ENV}"
}
#deactivate env
dac() {
source deactivate
env_var=""
}
env_info() {
if [[ ${env_var} == "" ]]
then
echo ""
else
echo "in ${env_var}"
fi
}
PS1="\u "
PS1+="$(env_info) \$";
Which is not working (my bash knowledge is only rudimentary sorry...).
env_info
always stays ""
no matter wether I call sac
or dac
in the terminal or not.
Question1: Why is the code not working?
Question2: Or is there maybe another way to get the current env-info in a - for this purpose - useful format?conda info --envs
returns to much info...
Go to the start menu, right-click 'Anaconda Prompt' and go to file location. Open its properties & change the target to the location of your preferred environment.
The method suggested in the comment from darthbith works very well. The variable $CONDA_DEFAULT_ENV
is exactly what I was looking for:
>>> source activate myEnv
>>> echo $CONDA_DEFAULT_ENV
myEnv
To add to the answer by A.Wenn, this is what I added to my custom prompt
PS1=""
# Add conda environment to prompt
if [ ! -z "$CONDA_DEFAULT_ENV" ]
then
PS1+="($CONDA_DEFAULT_ENV) "
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With