有什么方法可以将自定义别名添加到 pipenv shell 中吗?

Is there any way to add custom aliases into pipenv shell?

有没有什么方法可以配置 pipenv,使其在 shell 中加载自定义 bash 别名?

我试图将我的别名放入 .env 文件中,但这没有用。 之后我用谷歌搜索,但找不到解决方案。

遗憾的是,无法直接执行此操作。

如果您乐于使用 pipenv run 而不是 shell 别名,Pipenv 有一个几乎没有记录的 custom script shortcuts 功能;在你的 Pipfile 中加入类似这样的内容:

[scripts]
printfoo = "python -c \"print('foo')\""

然后 运行 pipenv run printfoo.

pipenv shell 似乎采用附加参数,这些参数作为初始命令发送到它启动的 shell。模拟的 session 如下:

$ cat tmp.sh
echo hi
$ pipenv shell . tmp.sh
Spawning environment shell (/bin/bash). Use 'exit' to leave.
. .../bin/activate
. . tmp.sh
$ . .../bin/activate
$ . tmp.sh
hi
$

由于 pipenv shell 只是启动了一个由 SHELL 环境变量命名的 shell 的交互式 session,您可以将代码添加到您通常的 .bashrc file 以获取 start-up 上的特殊本地文件,如果存在:

if [[ -f .pipenvshrc ]]; then
  . .pipenvshrc
fi

您还可以尝试使用 pipenv shell 添加到环境中的 $VIRTUAL_ENV 的值来选择源文件。