16

I have already studied this some time ago, but did not find any solution that would open terminal tabs, run some commands and then allow me to continue using those terminal tabs. All the ways I found launching terminal tabs from command line would only launch the tabs and not allow me to continue using them after that.

The problem I am trying to solve is that every time I need to boot my machine (or virtual machine in this case) I need to setup around six different terminal tabs to point to different folders and to export some environment variables on some of them.

I have experimented with xfce terminal and I have gotten some way with command like this:

terminal --disable-server -H --tab --title=1st_tab --tab --title=2nd_tab

But if I add command argument, the tab is not usable anymore when it opens:

terminal --disable-server -H --tab --title=1st_tab --tab --title=2nd_tab --command="cd ~/folder1"

http://docs.xfce.org/apps/terminal/command-line

I am currently using Red Hat Linux with gnome 2.28.2.

terdon
  • 54,564

3 Answers3

23

You can do this using GNOME terminator which is a great terminal with, among other things, the ability to split panes horizontally or vertically.

Once you have installed terminator you can set up a profile with your desired settings (instructions adapted from here):

  1. Run terminator, and set up the layout you want. You can use Ctrl+Shift+E to split windows vertically and Ctrl+Shift+O (that's O as in oodles, not zero) to split horizontally. For this example, I have created a layout with 6 panes:

enter image description here

  1. Right click on the terminator window and chose "Preferences". Once the Preferences window is open, go to "Layouts" and click "Add":

enter image description here

  1. That will populate the Layout list with your new layout:

enter image description here

  1. Find each of the terminals you have created in the layout, and click on them, then on the right enter the command you want to run in them on startup:

enter image description here

IMPORTANT: Note that the command is followed by ; bash. If you don't do that the terminals will not be accessible since they will run the command you give and exit. You need to launch a shell after each command to be able to use the terminals.

Once you have set all the commands click "Close" and then exit terminator.

  1. Open the terminator config file ~/.config/terminator/config and delete the section under layouts for the default config. Then change the name of the layout you created to default. It should look something like this:

     [global_config]
     [keybindings]
     [profiles]
       [[default]]
     [layouts]
       [[default]]
         [[[child0]]]
           position = 446:100
           type = Window
           order = 0
           parent = ""
           size = 885, 550
         [[[child1]]]
           position = 444
           type = HPaned
           order = 0
           parent = child0
         [[[child2]]]
           position = 275
           type = VPaned
           order = 0
           parent = child1
         [[[child5]]]
           position = 219
           type = HPaned
           order = 1
           parent = child1
         [[[child6]]]
           position = 275
           type = VPaned
           order = 0
           parent = child5
         [[[child9]]]
           position = 275
           type = VPaned
           order = 1
           parent = child5
         [[[terminal11]]]
           profile = default
           command = 'df -h; bash'
           type = Terminal
           order = 1
           parent = child9
         [[[terminal10]]]
           profile = default
           command = 'export foo="bar" && cd /var/www/; bash'
           type = Terminal
           order = 0
           parent = child9
         [[[terminal3]]]
           profile = default
           command = 'ssh -Yp 24222 cchapple@139.124.66.43'
           type = Terminal
           order = 0
           parent = child2
         [[[terminal4]]]
           profile = default
           command = 'top; bash'
           type = Terminal
           order = 1
           parent = child2
         [[[terminal7]]]
           profile = default
           command = 'cd /etc; bash'
           type = Terminal
           order = 0
           parent = child6
         [[[terminal8]]]
           profile = default
           command = 'cd ~/dev; bash'
           type = Terminal
           order = 1
           parent = child6
     [plugins]
    

The final result is that when you run terminator it will open with 6 panes, each of which has run or is running the commands you have specified:

enter image description here

terdon
  • 54,564
2

In order to have Terminator cd into a directory on launch, the command to configure is:

cd ~/someFolder; bash

This opens a terminal in the location cded to.

Actually, terdon does mention this in his post but it is buried in his wonderful mini-tutorial. It wasn't after I'd figured this out that I noticed it buried in his post, so I'm leaving this answer in order to emphasize.

terdon
  • 54,564
dotancohen
  • 11,720
0

The command must be followed by "; bash". Rest should be as per terdon's answers https://superuser.com/a/610048