Conda: how to modify conda 'source activate' ps1 behavior

Created on 27 Feb 2017  路  3Comments  路  Source: conda/conda

my current bash ps1 is as follows:

bldred='\e[1;31m' # Red
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
txtrst='\e[0m'    # Text Reset - Useful for avoiding color bleed

export PS1="\n\[$bldred\]\u\[$txtrst\]@\[$bldwht\]\h\[$txtrst\]:\[$bldcyn\]\w\[$txtrst\]$ "

However, running:

source activate <env-name-here>

by default, tells conda to prepend the env-name to my PS1:

(<env-name-here>)
user@short-domain:fullpath$

Is there a way to tell conda to insert the env-name within my PS1 instead, specifically, right after the newline?

stackoverflow post for this issue

source-community tag-shell type-feature

Most helpful comment

You can also just modify the line in the activate script. you'll find it in ${CONDA}/bin/. That way you can also customize the formatting. It would be pretty nice to have it as a config though (<- feature request? :D). Maybe I'll do it myself sometimes, if there's time.

All 3 comments

The simplest solution I have found is to move the newline from PS1 to PROMPT_COMMAND:

bldred='\e[1;31m' # Red
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
txtrst='\e[0m'    # Text Reset - Useful for avoiding color bleed

PROMPT_COMMAND="printf '\n'"
export PS1="\[$bldred\]\u\[$txtrst\]@\[$bldwht\]\h\[$txtrst\]:\[$bldcyn\]\w\[$txtrst\]$ "

This allows conda to maintain it's default PS1 behavior all while separating bash commands with newlines:

user@short-domain:fullpath$ source activate <env-name-here>

(<env-name-here>) user@short-domain:fullpath$

You can also just modify the line in the activate script. you'll find it in ${CONDA}/bin/. That way you can also customize the formatting. It would be pretty nice to have it as a config though (<- feature request? :D). Maybe I'll do it myself sometimes, if there's time.

xref #2747

Was this page helpful?
0 / 5 - 0 ratings

Related issues

garywu picture garywu  路  3Comments

jooh picture jooh  路  3Comments

mathoha picture mathoha  路  3Comments

kalefranz picture kalefranz  路  3Comments

mhlr picture mhlr  路  3Comments