如何更改默认Virtualenvwrapper提示 [英] How to Change Default Virtualenvwrapper Prompt

查看:267
本文介绍了如何更改默认Virtualenvwrapper提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何更改默认Virtualenvwrapper提示?默认情况下,工作在一个特定的虚拟环境像命令workon< _name_of_env_>prepends的virtualenv中你提示的名称。这可能会,如果你不使用默认的命令提示符下运行不佳。

How do you change the default Virtualenvwrapper prompt? By default, working on a particular virtual environment with a command like "workon <_name_of_env_>" prepends the name of the virtualenv to your prompt. This may work poorly if you're not using a default command prompt.

推荐答案

在默认情况下,当你切换到与该命令的virtualenvworkon&LT; name_of_env>,virtualenvwrapper prepends沿线串( &LT; name_of_env>)你的命令提示符。问题是,我把我的Bash提示符与行:

By default, when you switch into a virtualenv with the command "workon < name_of_env >", virtualenvwrapper prepends a string along the lines of "(< name_of_env >) " to your command prompt. The problem is that I set my Bash prompt with the lines:

PROMPT_COLOR1='0;36m'
PROMPT_COLOR2='1;34m'
PS1='\n\[\033[$PROMPT_COLOR1\](\t)\[\033[$PROMPT_COLOR2\] \u @ \w \n\[\033[$PROMPT_COLOR1\]$ \[\033[0;39m\]'

其中产量沿线的命令提示符:

Which yields a command prompt along the lines of:

< old_line >

(19:11:05) kevin @ ~/research 
$ 

切换到一个新的虚拟环境workon&LT; name_of_env>打开命令提示符是这样的:

Switching into a new virtual environment with "workon < name_of_env >" turned the command prompt to something like:

< old_line >
(< name_of_env >)
(19:11:05) kevin @ ~/research 
$ 

这比我想要的和错误的颜色来引导更多的混乱。我希望这样的事情:

Which was more cluttered than I wanted and the wrong color to boot. I was hoping for something like:

< old_line >

(< name_of_env >) (19:11:05) kevin @ ~/research 
$ 

伊恩Bicking已经previously指出,<一个href=\"http://stackoverflow.com/questions/3646014/changing-the-prompt-style-of-a-virtualenv-instance-with-zsh\">virtualenvwrapper's钩是,但我想我会后我的实际code到也许拯救别人一分钟上下行的解决方案。

Ian Bicking has previously pointed out that virtualenvwrapper's hooks were the solution but I figured I'd post my actual code to maybe save someone else a minute down the line.

我只不过是编辑文件$ WORKON_HOME / postactivate包括这些行:

I simply edited the file $WORKON_HOME/postactivate to include these lines:

# color virtualenv name properly and put it after the \n if there is one at the start of the prompt
if [ ${_OLD_VIRTUAL_PS1:0:2} == '\n' ]; then
    PS1="\n\[\033[$PROMPT_COLOR1\](`basename \"$VIRTUAL_ENV\"`) ${_OLD_VIRTUAL_PS1:2:${#_OLD_VIRTUAL_PS1}}"
else
    PS1="\[\033[$PROMPT_COLOR1\](`basename \"$VIRTUAL_ENV\"`) $_OLD_VIRTUAL_PS1 "
fi

和瞧!颜色和位置是正确的,当你直接从一个虚拟环境中切换到另一个(我没想到)。

and voila! The color and location are correct and it even works when you switch directly from one virtual environment to another (which I hadn't expected).

这篇关于如何更改默认Virtualenvwrapper提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆