我正在使用Ubuntu 9.04 x64,当我写:
gnome-terminal --tab
在终端,我希望它在同一终端窗口中打开一个新选项卡。但它开启了一个新的窗口。
我发现它的目的是在新窗口中打开一个新标签,即如果我写:
gnome-terminal --tab --tab
它将打开一个带有两个选项卡的新窗口。
所以,问题是,如何使用gnome-terminal
中的命令在当前窗口中打开一个新选项卡?
#!/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
这将自动确定相应的终端并相应地打开选项卡。
要在同一终端窗口中打开多个选项卡,您可以使用以下解决方案。
示例脚本:
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
您还可以让每个选项卡运行set命令。
gnome-terminal --tab -e "tail -f somefile" --tab -e "some_other_command"
我找到了最简单的方法:
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
更复杂的版本(从另一个窗口使用):
#!/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 #
为了汇集上面的许多不同点,这里是一个脚本,它将运行传递给脚本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"
以防万一,你想打开
干得好:
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
顺便说一句。)
我没有安装gnome-terminal,但您应该可以通过使用dbus-send在命令行上使用DBUS调用来完成此操作。
考虑使用Roxterm。
roxterm --tab
在当前窗口中打开一个选项卡。
对于任何寻求不使用命令行的解决方案的人:ctrl + shift + t