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

1

14

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.

Reformation answered 11/10, 2018 at 16:12 Comment(6)
Did you get any answer to that ? I'm in trouble too with gnome-terminal and some light on your problem might be helpfull for me as well.Motel
@Louisb Unfortunately nothing yet.Reformation
Do you have any update on this?Houseyhousey
@NahuelBarrios Unfortunately nothing yet.Reformation
I think this fits better on Unix & LinuxAblaut
@Ablaut - Posted on Unix & Linux (unix.stackexchange.com/questions/492365/…)Reformation
R
13

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.

Ruthful answered 3/1, 2019 at 15:24 Comment(2)
Thanks, very helpful answer! I have spend some thoughts on how to streamline your solution, posted as answer to the other question on Unix & LinuxAcquiesce
@Acquiesce I ended up switching to Terminator after this change.Ruthful

© 2022 - 2024 — McMap. All rights reserved.