sudo apt-get install xdotool
我通过运行并抛出 命令来安装 xdotool,xdotool key ctrl+alt+t
以从当前终端窗口打开一个新的终端窗口。但它不起作用。
从当前 gnome-terminal 打开新终端窗口的命令是什么?
答案1
只需这个命令就可以:
gnome-terminal
通常,如果你想要一个命令从终端打开并分离(因此它返回到提示符而不必关闭打开的程序),你必须使用这样的东西:
gnome-terminal & disown
但是父终端似乎检测到正在使用相同的命令,因此您无需这样做,这样gnome-terminal
就足够了。xfce4-terminal
从 Xfce 的终端和KDE 的终端运行时似乎也会发生这种情况(从konsole
运行时似乎不起作用(另请参阅xterm
xterm
xterm xterm
) -konsole
从 Gnome/Unity 和 Xfce 的终端运行以及,但对于 Xfce 的终端(在 gnome 终端中),您需要xfce4-terminal & disown
)。
更多详情请访问gnome-terminal
的手册页:
gnome-terminal [-e, --command=STRING] [-x, --execute ] [--window-with-profile=PROFILENAME] [--tab-with-profile=PRO‐
FILENAME] [--window-with-profile-internal-id=PROFILEID] [--tab-with-profile-internal-id=PROFILEID] [--role=ROLE]
[--show-menubar] [--hide-menubar] [--geometry=GEOMETRY] [--disable-factory] [-t, --title=TITLE] [--working-direc‐
tory=DIRNAME] [--usage] [-?, --help]
答案2
从当前终端打开新终端窗口的命令,
xdotool key ctrl+shift+n
安装xdotool
,
sudo apt-get install xdotool
答案3
以下脚本将在当前 gnome-terminal 窗口中打开一个新选项卡,并可选择为该选项卡添加标题。此操作可从任何窗口运行,您不必在 gnome-terminal 窗口中运行它。并且,如果没有 gnome-terminal 正在运行,它将启动一个。唯一需要注意的是,如果您更改了打开新选项卡的热键,则可能必须更改该行xdotool key ctrl+T
以使用您的热键。
#!/bin/bash
DELAY=1
# get title we are going to set tab too, default to Terminal
title="Terminal"
if [ $# -eq 1 ]; then
title="$1"
fi
# get pid of running terminal server
TPID=$(ps -C gnome-terminal-server -o pid | tail -1 | sed -e's/\s//g')
if [ ${TPID} == "PID" ]; then
# no terminal process running yet, so just start one
gnome-terminal -t "$title" --tab
exit 0
fi
# there is a terminal, get window id of the running terminal server
WID=$(wmctrl -lp | awk -v pid=$TPID '$3==pid{print $1;exit;}')
# get title of currently active tab
TTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
if [ "$TTITLE" == "\"Terminal\"" ]; then
# so we don't go into an infinite loop later
TTITLE="we had a terminal named terminal $$"
fi
# get focus on active terminal tab
xdotool windowfocus $WID
# use keyboard shortcut to open new tab
xdotool key ctrl+T
# see if we have created tab and are in terminal
NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
waited=0
while [ "$TTITLE" == "$NTITLE" ]; do
# sleep for 1 second before we try again
xdotool sleep 1
NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
if [ $waited == 0 ]; then
echo "Waiting "
waited=1
fi
echo -n "."
done
if [ $waited == 1 ]; then
echo ""
fi
# active tab is the new one we created, wait DELAY seconds just to be sure we can type into it to set tab name
xdotool sleep $DELAY
xdotool type --clearmodifiers "termtitle $title"
xdotool key Return
# make tab the active window and raise it to top
wmctrl -i -a $WID
exit 0