linux命令行启动新终端,linux - 使用命令行在gnome-terminal中打开一个新选项卡

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

当我写作

gnome-terminal

在终端,我希望它在同一终端窗口中打开一个新选项卡。 但它开启了一个新的窗口。

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

gnome-terminal

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

那么,问题是,如何使用gnome-terminal中的命令在当前窗口中打开新选项卡?

我使用的是Ubuntu 9.04 x64。

10个解决方案

67 votes

您还可以让每个选项卡运行set命令。

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

Chase Seibert answered 2019-07-07T10:58:33Z

63 votes

#!/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

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

utkarsh dubey answered 2019-07-07T10:58:09Z

5 votes

我找到了最简单的方法:

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

jaogoy answered 2019-07-07T10:59:07Z

3 votes

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

#!/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 #

jno answered 2019-07-07T10:59:34Z

1 votes

为了汇集上面的许多不同点,这里有一个脚本将运行传递给脚本./new_tab.sh "watch ls -l"的任何参数:

#!/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;

接下来让它可执行:    ./new_tab.sh "watch ls -l"

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

NeoGeek answered 2019-07-07T11:00:14Z

0 votes

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

Mike McQuaid answered 2019-07-07T11:00:39Z

0 votes

考虑使用Roxterm。

roxterm --tab

在当前窗口中打开一个选项卡。

user25643 answered 2019-07-07T11:01:13Z

0 votes

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

Jemini answered 2019-07-07T11:01:41Z

0 votes

以防万一,你想打开

一个新窗口

有两个标签

并在那里执行命令

让他们保持开放......

干得好:

gnome-terminal --geometry=73x16+0+0 --window \

--working-directory=/depot --title='A' --command="bash -c ls;bash" \

--tab --working-directory=/depot/kn --title='B' --command="bash -c ls;bash"

(同样适用于mate-terminal顺便提一下。)

Frank Nocke answered 2019-07-07T11:02:51Z

-2 votes

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

示例脚本:

pwd='/Users/pallavi/Documents/containers/platform241/etisalatwallet/api-server-tomcat-7/bin'

pwdlog='/Users/pallavi/Documents/containers/platform241/etisalatwallet/api-server-tomcat-7/logs'

pwd1='/Users/pallavi/Documents/containers/platform241/etisalatwallet/core-server-jboss-7.2/bin'

logpwd1='/Users/pallavi/Documents/containers/platform241/etisalatwallet/core-server-jboss-7.2/standalone/log'

osascript -e "tell application \"Terminal\"" \

-e "tell application \"System Events\" to keystroke \"t\" using {command down}" \

-e "do script \"cd $pwd\" in front window" \

-e "do script \"./startup.sh\" in front window" \

-e "tell application \"System Events\" to keystroke \"t\" using {command down}" \

-e "do script \"cd $pwdlog\" in front window" \

-e "do script \"tail -f catalina.out \" in front window" \

-e "tell application \"System Events\" to keystroke \"t\" using {command down}" \

-e "do script \"cd $pwd1\" in front window" \

-e "do script \"./standalone.sh\" in front window" \

-e "tell application \"System Events\" to keystroke \"t\" using {command down}" \

-e "do script \"cd $logpwd1\" in front window" \

-e "do script \"tail -f core.log \" in front window" \

-e "end tell"

> /dev/null

Pallavi Varne answered 2019-07-07T11:03:19Z

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值