使用命令行在gnome-terminal中打开一个新选项卡

时间:2009-07-27 15:48:34

标签: linux ubuntu console terminal

写作时

  

gnome-terminal --tab

在终端,我希望它在同一个终端窗口中打开一个新标签。但它会打开一个新窗口。

我发现它的目的是在新窗口中打开一个新标签,即如果我写

  

gnome-terminal --tab --tab

它会打开一个带有两个标签的新窗口。

因此,问题是,如何使用gnome-terminal中的命令在当前窗口中打开新标签?

我正在使用Ubuntu 9.04 x64。

9 个答案:

答案 0 :(得分:67)

您还可以让每个标签运行一个set命令。

gnome-terminal --tab -e "tail -f somefile" --tab -e "some_other_command"

答案 1 :(得分:63)

#!/bin/sh

WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool key ctrl+shift+t
wmctrl -i -a $WID

这将自动确定相应的终端并相应地打开选项卡。

答案 2 :(得分:5)

我找到了最简单的方法:

gnome-terminal --tab -e 'command 1' --tab -e 'command 2'

我使用tmux而不是直接使用终端。所以我想要的是一个简单的命令/ shell文件来构建带有几个env窗口的开发tmux。 shell代码如下:

#!/bin/bash
tabs="adb ana repo"
gen_params() {

    local params=""
    for tab in ${tabs}
    do  
        params="${params} --tab -e 'tmux -u attach-session -t ${tab}'"
    done
    echo "${params}"
}
cmd="gnome-terminal $(gen_params)"
eval $cmd

答案 3 :(得分:3)

更复杂的版本(从另一个窗口使用):

#!/bin/bash

DELAY=3

TERM_PID=$(echo `ps -C gnome-terminal -o pid= | head -1`) # get first gnome-terminal's PID
WID=$(wmctrl -lp | awk -v pid=$TERM_PID '$3==pid{print $1;exit;}') # get window id

xdotool windowfocus $WID
xdotool key alt+t # my key map
xdotool sleep $DELAY # it may take a while to start new shell :(
xdotool type --delay 1 --clearmodifiers "$@"
xdotool key Return

wmctrl -i -a $WID # go to that window (WID is numeric)

# vim:ai
# EOF #

答案 4 :(得分:1)

为了汇集上面的许多不同点,这里是一个脚本,它将运行传递给脚本vim new_tab.sh的任何参数:

#!/bin/bash
#
# Dependencies:
#   sudo apt install xdotool

WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool key ctrl+shift+t
wmctrl -i -a $WID
sleep 1; xdotool type --delay 1 --clearmodifiers "$@"; xdotool key Return;

接下来让它可执行:     chmod +x new_tab.sh

现在,您可以使用它在新标签中运行您想要的任何内容:     ./new_tab.sh "watch ls -l"

答案 5 :(得分:0)

我没有安装gnome-terminal,但您可以使用dbus-send在命令行上使用DBUS调用来完成此操作。

答案 6 :(得分:0)

请考虑使用Roxterm。

roxterm --tab

在当前窗口中打开一个标签。

答案 7 :(得分:0)

对于任何寻求不使用命令行的解决方案的人:ctrl + shift + t

答案 8 :(得分:-2)

要在同一终端窗口中打开多个标签,您可以使用以下解决方案。

示例脚本:

<
相关问题