具有不同 Virtualenvs 的两个 XTerm

Two XTerm with Different Virtualenvs

我的 Ubuntu 桌面上有两个 XTerm 终端。我的目标是在打开第一个时激活 py2 virtualenv,在打开第二个时激活 py3。

试图通过更改 [Desktop Entry] 下的 Exec 行来操纵行为,但没有成功

[Desktop Entry]
Name=PY2-VENV
Exec=uxterm && source /home/user/py2-venv/bin/activate
Terminal= true
.
.
.

知道怎么做吗?

你的意思可能是

Exec=uxterm

(用于设置 xterm 的 shell 脚本)而不是

Exec=uterm

然而,&& 可能不起作用,因为 desktop specification 调用可以直接转换为 execvp 调用:

The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments. The executable program can either be specified with its full path or with the name of the executable only. If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment. The name or path of the executable program may not contain the equal sign ("="). Arguments are separated by a space.

Arguments may be quoted in whole. If an argument contains a reserved character the argument must be quoted. The rules for quoting of arguments is also applicable to the executable name or path of the executable program as provided.

假设您的 shell 是 bash,您可以使用其注释行选项指向不同的 shell 初始化文件:

   --init-file file                                                         
   --rcfile file                                                            
          Execute  commands  from file instead of the system wide initial‐  
          ization file /etc/bash.bashrc and the standard personal initial‐  
          ization  file ~/.bashrc if the shell is interactive (see INVOCA‐  
          TION below). 

类似这样的东西,例如:

Exec=uxterm -e bash --rcfile /home/user/py2-venv/bin/activate