如何在bash/Python/Fabric/sh脚本中使用pew?

如何在bash/Python/Fabric/sh脚本中使用pew?,python,bash,shell,virtualenv,Python,Bash,Shell,Virtualenv,我最近开始使用而不是+ 在交互式shell中工作时,这是一个不错的选择。然而,我仍然在bash脚本[1]中使用virtualenvwrapper,并且我正在考虑编写一些支持virtualenv的Python脚本[2] 鉴于pew-workon启动了一个新的提示符,我可以在shell[3]和Python脚本中使用它吗?如果是,怎么做 [1] 使用下面的代码片段,这正是我想要摆脱的: # make sure we can workon (the path is Ubuntu-specific) [[

我最近开始使用而不是+

在交互式shell中工作时,这是一个不错的选择。然而,我仍然在bash脚本[1]中使用virtualenvwrapper,并且我正在考虑编写一些支持virtualenv的Python脚本[2]

鉴于
pew-workon
启动了一个新的提示符,我可以在shell[3]和Python脚本中使用它吗?如果是,怎么做

[1] 使用下面的代码片段,这正是我想要摆脱的:

# make sure we can workon (the path is Ubuntu-specific)
[[ $(type -t workon) == "function" ]] || source /etc/bash_completion.d/virtualenvwrapper
[2] 我仍在研究哪种普通Python最适合我的需要


[3] 私下里,我更喜欢在fish中使用它,而不是bash中,但这似乎很深奥:)

我个人只在交互式shell中使用pew,但有些脚本中有一些命令可用于使用pew。让我们以此为例:

>cat script.sh
#!/bin/bash
which python    
您可以使用
in
命令在virtualenv中执行任意代码:

pew in env which python
pew in env ./script.sh
(这两个将做相同的事情)

您还可以使用
-d
标志来避免在创建时激活它,因此您可以在如下脚本中使用pew:

pew new -d yourenv > /dev/null
pew in yourenv which python
我不认为在shell脚本中使用这样的东西会给您带来任何真正的优势:如果您有这样的东西

#!/bin/sh
. ~/.virtualenvs/yourenv/bin/activate
which python
源代码脚本不会污染源代码脚本之外的内容

OTOH:使用pew或VirtualEnvrapper可能有助于执行复制/重命名环境等任务。任何未以
调用(inve)
结尾的命令都可以正常使用,对于其他命令(new、mkproject、mktmpenv、cp),应该有一个
--not activate
标志可用

(我刚刚意识到cp命令没有
-d
标志,我可能需要很快添加它)

编辑:更多示例

> pew new -d dummy -i e
> pew in dummy python -me 2 "**" 53
dummy:
9007199254740992
> pew in dummy python helloworld.py 
dummy:
helloworld