bash 如何修改 conda 'source activate' ps1 行为
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42481726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to modify conda 'source activate' ps1 behavior
提问by jkarimi
my current bash ps1 is as follows:
我目前的 bash ps1 如下:
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
:
默认情况下,告诉conda
在env-name
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?
有没有办法告诉在我conda
的env-name
内部插入PS1
,特别是在换行符之后?
采纳答案by jkarimi
The simplest solution I have found is to move the newline from PS1
to PROMPT_COMMAND
:
我发现的最简单的解决方案是将换行符从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:
这允许conda
在PS1
使用换行符分隔 bash 命令的同时保持其默认行为:
user@short-domain:fullpath$ source activate <env-name-here>
(<env-name-here>) user@short-domain:fullpath$
回答by remram
Conda has a setting to disable changing the prompt: changeps1: False
(in ~/.condarc
). You can then add this yourself ($(basename "$CONDA_PREFIX")
).
Conda 有一个禁止更改提示的设置:changeps1: False
(in ~/.condarc
)。然后您可以自己添加它 ( $(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.
这类似于virtualenv,如果$VIRTUAL_ENV_DISABLE_PROMPT
设置了则不会更新提示,因此您可以$(basename "$VIRTUAL_ENV")
自己打印。