Python 使用多个virtualenv选项卡和服务启动gnome终端,并预先命名

Python 使用多个virtualenv选项卡和服务启动gnome终端,并预先命名,python,terminal,virtualenv,gnome-terminal,Python,Terminal,Virtualenv,Gnome Terminal,我正在从事一个服务器端项目,该项目由几个服务组成。每个服务都以交互(即非守护进程)模式运行,这在主动开发时非常方便。该项目是虚拟的。因此,启动服务的典型方式是: $ cd ~/to/vitualenv/subdir/where/service/code/located $ source ../path/to/virtualenv/bin/activate $ ./script-to-start-service + Set title of terminal to the service name

我正在从事一个服务器端项目,该项目由几个服务组成。每个服务都以交互(即非守护进程)模式运行,这在主动开发时非常方便。该项目是虚拟的。因此,启动服务的典型方式是:

$ cd ~/to/vitualenv/subdir/where/service/code/located
$ source ../path/to/virtualenv/bin/activate
$ ./script-to-start-service
+ Set title of terminal to the service name via GUI
如果有2-3个服务就可以了。但是我们有一打。在电脑重新启动后重新启动它们真的很痛苦

所以我想要的是一个脚本,一旦执行它,就会打开一个新的gnome终端窗口,其中有十几个命名选项卡(每个服务一个),每个选项卡中都有激活的virtualenv,并在这些选项卡中运行一组服务实例。到目前为止,我得到的最好结果是:

$ gnome-terminal --working-directory=~/to/vitualenv/subdir --window --tab --tab
--title和--profile看起来被忽略了,如果指定了--command,新打开的窗口将在打开后立即关闭

有什么想法吗?如何找到激活脚本的来源、提供标题和运行服务


另外,它仅用于开发目的,不用于实际服务器上的部署。

以下内容适用于我,并按照您的要求执行:


gnome终端--working directory=/path/to/wd--tab with profile=profile1--title=title1-e'bash--rcfile/path/to/rcfile1.sh'--tab with profile=profile2--title=title2-e'bash--rcfile/path/to/rcfile2.sh'
创建一个名为“服务”的gnome终端配置文件(编辑>配置文件>新建)

在“编辑>配置文件首选项>标题和命令>运行自定义命令而不是我的shell”中,将自定义命令设置为:

bash --rcfile ../path/to/virtualenv/bin/activate
然后使用gnome终端启动您的服务。以下命令在不同目录的选项卡中启动两个
yes
实例。我已将命令分为三行,但您应将其作为一行输入

gnome-terminal
--tab-with-profile=service --working-directory=/home/$USER/data --title="feelgood" --command="yes"
--tab-with-profile=service --working-directory=/code --title="negative" --command="yes no"

您可能希望创建一个文件作为自定义命令,而不是直接调用activate:

source ~/.bashrc
source ../path/to/virtualenv/bin/activate

您还可以添加命令(如更改目录或启动服务)。请注意,每次使用该配置文件打开终端时,都会执行这些命令。

Wow!顶多也行。但是有没有办法扔掉rcfile*.sh文件呢?用管子之类的