Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening new gnome-terminal (v3.28+) with multiple tabs and different commands

It seems the behavior of gnome-terminal has changed between the version shipped with Ubuntu 14 (v3.6?) and Ubuntu 18 (v3.28).

I have a script that opens a new gnome-terminal with a bunch of tabs setup to different directories for my development, and currently the first tab runs a script. The command to open the gnome-terminal with tabs looks something like this:

gnome-terminal \
   --tab --command="myscript.sh" \
   --tab --working-directory="<some dir 1>" \
   --tab --working-directory="<some dir 2>" \
   ...

This works perfectly as desired in the gnome-terminal version that shipped with Ubuntu 14 (v3.6?).

But in the gnome-terminal version that ships with Ubuntu 18 (v3.28) several things have changed:

  1. Unless I add the --window option, the tabs open in the current gnome-terminal, not a new one. Unfortunately adding the --window option opens an initial blank tab. Is it possible to open a new window with only the tabs that I specify?
  2. I now get the following notice (though it functions as before):

    # Option “--command” is deprecated and might be removed in a later version of gnome-terminal.
    # Use “-- ” to terminate the options and put the command line to execute after it.
    

    Changing my script per this guidance changes the behavior such that the command is issued to all tabs, whereas before I could apply a unique command to each tab. Does this mean the ability to run a separate command per tab has been deprecated, or am I missing something?

I appreciate suggestions on how to change my script to support the old behavior in the newer gnome-terminal.

like image 922
codesniffer Avatar asked Oct 11 '18 16:10

codesniffer


People also ask

How do I switch between tabs in GNOME Terminal?

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 make multiple tabs 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.

How do I open multiple terminal tabs in Linux?

The easiest way to invoke the terminal is to use the key combination ctrl+alt+t. You will notice that each time you start a new terminal, it opens in a separate window. However, the terminal gives you the option to start new terminal sessions as tabs in the same terminal window.

How do I create a new terminal tab?

In the Terminal app on your Mac, do one of the following: Press Command-T. Choose Shell > New Tab > New Tab with Profile. The name of the profile that opens is concatenated to the end of the New Tab with Profile menu item.


1 Answers

1) Use --window for your first tab

gnome-terminal \
   --window -t 'Tab 1' \
   --tab -t 'Tab2' --working-directory="<some dir 1>" \
   --tab -t 'Tab3' --working-directory="<some dir 2>" \
   ...

Unfortunately this will only allow one command to be passed in using the new design, and the window/tabs close at completion (I'm not sure if that was the behavior before)

2) If you don't care about the tab closing when the command is complete, you could do this:

$ gnome-terminal --window -- ./mytabs.sh

mytabs.sh

#!/bin/bash
gnome-terminal --tab -t 'Tab 1' -- ./myscript.sh
gnome-terminal --tab -t 'Tab 2' --working-directory="<some dir 1>"
gnome-terminal --tab -t 'Tab 3' --working-directory="<some dir 2>"

This will open each tab from the script in the window that was created in the code above it. It's a pain in that you either have to type out the first command or create a second script.

like image 148
rtaft Avatar answered Oct 28 '22 08:10

rtaft