caiogondim / bullet-train.zsh

:bullettrain_side: An oh-my-zsh shell theme based on the Powerline Vim plugin
MIT License
2.82k stars 382 forks source link

anaconda virtualenv doesn't  display properly #282

Open karterotte opened 6 years ago

karterotte commented 6 years ago

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!

ferreirafabio commented 5 years ago

screen shot 2018-08-30 at 19 52 15 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

salmanulfarzy commented 5 years ago

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
Angryrou commented 4 years ago

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.

  1. add one line in the scope of BULLETTRAIN_PROMPT_ORDER.
    # 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
  2. add the related promot function 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
    }

Add following lines

CONDA

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.
jrwrigh commented 4 years ago

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
}
maxim-sm commented 3 years ago

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
}
Jinsung-L commented 1 year ago

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
}