3

我目前正在编写一个脚本来在 gnome-terminal 中打开几个选项卡,并设置它们的标题。我可以打开多个选项卡,但我需要将焦点更改为这些选项卡(以编程方式),以便从我的脚本中设置它们的标题。

我交替使用 zsh 和 bash,所以任何 bash 命令都应该可以正常工作。我开始熟悉xdotooland wmctrl,但不确定将焦点切换到打开选项卡的命令组合。

我可以使用哪些命令从 gnome-terminal CLI “切换到下一个打开的选项卡”或“切换到选项卡N ”?

4

3 回答 3

3

为了从 Bash Shell 发送信号,请使用xdotool

sudo apt install xdotool

在您的脚本中发出以下命令:

xdotool key Control+Page_Up
于 2019-04-19T12:41:11.050 回答
1

您可以在打开它们时设置选项卡的标题:

gnome-terminal --geometry=80x25+0+0 --window --working-directory=<Firtst Tab Dir> \
               --title='<First Tab Title>' --command="bash" \
               --tab --working-directory=<Second Tab Dir> --title='<Second Tab Title>' \
               --command="bash" and so on...

我会发表评论,但没有足够的声誉,但是

于 2019-08-15T10:18:15.077 回答
0

我用xdotool解决了这个问题

在一行中,首先,使用key命令打开一个新选项卡。默认行为是将焦点切换到此选项卡。然后,使用该type命令在新选项卡中运行函数、脚本或其他程序。最后,使用key命令“按回车键”。重复 N 个标签!

# inside a file loaded by .bashrc which contains all my functions:
function setupterm() {
  # run a command, like set a title, in the current window/tab
  customCommandOne
  # do the needful as described above
  xdotool key Control+Shift+t && xdotool type customCommandTwo && xdotool key Return
  # repeat for n-many tabs
  xdotool key Control+Shift+t && xdotool type customCommandThree && xdotool key Return
  # return focus to first tab
  xdotool key Control+Page_Down
}
于 2019-09-07T00:36:34.747 回答