Open karterotte opened 6 years ago
Same issue here. When I source virtual environments, 'system' turns into the env name but not for conda environments. How to fix this? Thank you
Looks like current implementation doesn't support conda
environments.
It could be modified to support conda
by using CONDA_DEFAULT_ENV
to get environment name. Also you've to disable prompt set by conda
(shows up before the theme surrounded with brackets) with
conda config --set changeps1 False
I modified the theme file ~/.oh-my-zsh/custom/themes/bullet-train.zsh-theme
in the following three steps. Please make sure you are not using virtualenv
to manage your python virtual env, otherwise you may be confused by two different descriptions of the python enviroment.
# Define order and content of prompt
if [ ! -n "${BULLETTRAIN_PROMPT_ORDER+1}" ]; then
BULLETTRAIN_PROMPT_ORDER=(
time
status
custom
context
dir
screen
perl
ruby
virtualenv
conda # <-- ADD
nvm
aws
go
rust
elixir
git
hg
cmd_exec_time
)
fi
prompt_conda()
under prompt_virtualenv()
# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment $BULLETTRAIN_VIRTUALENV_BG $BULLETTRAIN_VIRTUALENV_FG $BULLETTRAIN_VIRTUALENV_PREFIX" $(basename $virtualenv_path)"
elif which pyenv &> /dev/null; then
prompt_segment $BULLETTRAIN_VIRTUALENV_BG $BULLETTRAIN_VIRTUALENV_FG $BULLETTRAIN_VIRTUALENV_PREFIX" $(pyenv version | sed -e 's/ (set.*$//' | tr '\n' ' ' | sed 's/.$//')"
fi
}
prompt_conda() { prompt_segment $BULLETTRAIN_VIRTUALENV_BG $BULLETTRAIN_VIRTUALENV_FG $BULLETTRAIN_VIRTUALENV_PREFIX" $(conda info | awk '{print $4}' | sed -n '2p')" }
3. make the previous conda invisiable by adding `changeps1: false` in your `~/.condarc` file.
I edited @Angryrou's command slightly so that if there isn't an environment activated, it doesn't display anything:
# CONDA
# Taken from https://github.com/caiogondim/bullet-train.zsh/issues/282#issuecomment-516266791
prompt_conda() {
if [[ ! $(conda info | awk '{print $4}' | sed -n '2p') == 'None' ]]; then
prompt_segment $BULLETTRAIN_VIRTUALENV_BG $BULLETTRAIN_VIRTUALENV_FG $BULLETTRAIN_VIRTUALENV_PREFIX" $(conda info | awk '{print $4}' | sed -n '2p')"
fi
}
Thanks @Angryrou and @jrwrigh for your solutions. I found the command "conda info" to be very slow on my machine so I wrote a different solution that uses the $CONDA_PREFIX variable. Hope it helps someone. NOTE: My solution removes $BULLETTRAIN_VIRTUALENV_PREFIX and sets $BULLETTRAIN_VIRTUALENV_FG to black just because I like it this way.
prompt_conda() {
prefix=$(echo $CONDA_PREFIX | grep -o '[^/]*$')
[[ -z $prefix ]] && return
[[ $prefix = 'anaconda3' ]] && prefix='base'
prompt_segment $BULLETTRAIN_VIRTUALENV_BG black $prefix
}
Thanks to @Angryrou and @jrwrigh and @maxim-sm and @salmanulfarzy for your solutions.
I found out that I can use CONDA_DEFAULT_ENV
to get the currently active conda environment.
This solution does not display anything if the base environment is activated or there's no active environment.
# Conda: current working env
prompt_conda() {
if [[ -n $CONDA_DEFAULT_ENV && ! $CONDA_DEFAULT_ENV == 'base' ]]; then
prompt_segment $BULLETTRAIN_VIRTUALENV_BG $BULLETTRAIN_VIRTUALENV_FG $BULLETTRAIN_VIRTUALENV_PREFIX" $CONDA_DEFAULT_ENV"
fi
}
the virtual env name doesn't display in powerline but like this:
11:28:59 XXX@XXX ~ <----it's powerline $ vim /etc/bashrc (test_env)
I want to know how to fix it ,THANKS!