Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to modify conda 'source activate' ps1 behavior

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?

like image 576
jkarimi Avatar asked Feb 27 '17 09:02

jkarimi


2 Answers

Conda has a setting to disable changing the prompt: changeps1: False (in ~/.condarc). You can then add this yourself ($(basename "$CONDA_PREFIX")).

This is similar to virtualenv, which doesn't update the prompt if $VIRTUAL_ENV_DISABLE_PROMPT is set, so you can print $(basename "$VIRTUAL_ENV") yourself.

like image 96
remram Avatar answered Oct 15 '22 14:10

remram


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

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$
like image 28
jkarimi Avatar answered Oct 15 '22 15:10

jkarimi