Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a new tab in GNOME Terminal from command line? [closed]

People also ask

How do I open a closed tab in Linux terminal?

Now when you connect to the machine via SSH, just type screen and press Space. You will be back to your normal terminal.

How do I switch between tabs in gnome terminal?

3 Answers. You can switch the tabs using Ctrl + PgDn to next tabs and Ctrl + PgUp for the previous tabs. Reordering can be done using Ctrl + Shift + PgDn and Ctrl + Shift + PgUp .

How do I add a tab in terminal?

For example, if you have your preferences set to open a new terminal in a new tab, then pressing New Terminal will open a new tab. On the other hand, if you hold down Ctrl and then press New Terminal, then a new window will be opened instead.


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

This will auto determine the corresponding terminal and opens the tab accordingly.


You can also have each tab run a set command.

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

I found the simplest way:

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

I use tmux instead of using terminal directly. So what I want is really a single and simple command/shell file to build the development env with several tmux windows. The shell code is as below:

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

A bit more elaborate version (to use from another window):

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

Just in case, you want to open

  • a new window
  • with two tabs
  • and executing command in there
  • and having them stay open...

here you go:

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"

(same for mate-terminal btw.)


For anyone seeking a solution that does not use the command line: ctrl+shift+t