设置终端标签标题

omn*_*nse 11 gnome-terminal

我正在尝试在 gnome-terminal 中打开几个终端选项卡,到目前为止我已经设法做一些事情,但我现在被卡住了。

所以,我有以下要求:

  • 打开标题为“X”和“Y”的标签
  • 执行一些命令
  • 保持标签打开并准备好进一步使用;保留标题。

到目前为止,我设法满足了一些要求,但不是全部:

gnome-terminal --tab -t "X" -e "bash" --tab -t "Y" -e "top"
Run Code Online (Sandbox Code Playgroud)

这将打开两个选项卡:

  1. “X”(然后将标题更改为默认标题)
  2. “Y”,但选项卡在我退出后立即关闭top

有没有办法打开一个选项卡,启动bash,但更改标题?我试过谷歌,但放弃了。

编辑:它不一定是命令。

Syl*_*eau 6

要保留标签标题,您需要在您的 中注释以下几行.bashrc

# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
#    ;;
#*)
#    ;;
#esac
Run Code Online (Sandbox Code Playgroud)

然后gnome-terminal --tab -t "X" -e "bash" --tab -t "Y" -e "top"将按预期工作:

在此处输入图片说明


Rma*_*ano 4

正如您在其他答案中看到的,每次输出提示时,选项卡的标题都会由 shell 更改。执行top选项卡后退出,因为您告诉它运行的命令完成了......

我将执行以下操作:

步骤1:使用shell调用终端,添加环境变量,如下所示:

gnome-terminal --tab -t X -e "env MYTAB=X bash" --tab -t Y -e "env MYTAB=Y bash" 
Run Code Online (Sandbox Code Playgroud)

步骤 2:在末尾添加.bashrc以下代码:

#if MYTAB is not set, return
[ -z "$MYTAB" ] && return
# reset the cursor and title 
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1="\[\e]0;$MYTAB \w\a\]$PS1"   #title: $MYTAB and current dir
# execute the commands for every tab
case "$MYTAB" in
        X)
                echo this is X
        ;;

        Y)
                echo this is Y 
                top
        ;;
esac
Run Code Online (Sandbox Code Playgroud)

...我认为这很容易理解,您可以使用所需的命令/调整进行修改。经测试,工作正常;退出top该选项卡后,您仍然会看到提示和选项卡供您仔细阅读。

屏幕截图(在 中按“q”后top):

截屏