26

I would like to open a terminal, split it to lets say 9 parts (3x3) and execute some bash script. But for each terminal part different script.

Can this be done using perl, python or even bash?

How can I switch between those little terminals without using keyboard shortcuts?

Oh, by the way, I'm using terminator. And if there is some other terminal emulator that enables such a functionality, which is it?

jirislav
  • 403
  • terminator is not a shell. There are two different terminal emulators called terminator (only one of which I believe can split the screen). – Stéphane Chazelas Nov 17 '14 at 15:11
  • Ah, thanks .. then I'd like to know how to split terminator using script? :) And switch between those parts? – jirislav Nov 17 '14 at 15:13
  • 1
    I've never used it and don't have the time to research it right now, but I think (not sure though) that byobu could help you if you're running the terminals on a remote system -- see https://help.ubuntu.com/community/Byobu. Byobu runs on many *nix distributions – Clive van Hilten Nov 17 '14 at 15:20
  • 1
    As @ClivevanHilten mention and answered here it can be done with friendly Byobu (which by default sit on top of tmux). – Pablo A May 24 '17 at 22:55

4 Answers4

47

To plagiarize myself, 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

  2. Right click on the terminator window and choose Preferences. Once the Preferences window is open, go to Layouts and click Add:

    enter image description here

  3. That will populate the Layouts list with your new layout:

    enter image description here

  4. 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.

  5. 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

Also, you can set up as many different profiles as you wish and either launch terminator with the -p switch giving a profile name, or manually switch to whichever profile you want after launching.

terdon
  • 242,166
6

Are you searching for terminal multiplexer tmux.

https://github.com/tmux/tmux

4

Back when I was using terminator this is the rc file that I used to open a bunch of terminals and run applications. Save it to .config/terminator/config.

[global_config]
  title_hide_sizetext = True
  enabled_plugins = LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
[keybindings]
[profiles]
  [[default]]
    font = DejaVu Sans Mono 9
    cursor_blink = False
    scrollback_infinite = True
[layouts]
  [[default]]

    [[[root]]]
      position = -4:0
      type = Window
      order = 0 
      parent = ""
      size = 1072, 1884

    [[[grand]]]
      position = 536 
      type = HPaned
      order = 0 
      parent = root
    [[[left]]]
      position = 942 
      type = VPaned
      order = 0 
      parent = grand
    [[[right]]]
      position = 942 
      type = VPaned
      order = 1 
      parent = grand



    [[[terminal1]]]
      profile = default
      type = Terminal
      order = 0 
      parent = left
      command = "cd ~/code/foo; bash"
    [[[terminal2]]]
      profile = default
      type = Terminal
      order = 1 
      parent = left
      command = "cd ~/bar/baz; bash"



    [[[terminal3]]]
      profile = default
      type = Terminal
      order = 1 
      parent = right
      command = ""
    [[[terminal4]]]
      profile = default
      type = Terminal
      order = 0 
      parent = right
      command = "cmus; bash"



[plugins]

EDIT: Note that this information probably came from Terdon's post on a much earlier thread. I've been using this setup for a few months, but Terdon's post here looks very familiar!

dotancohen
  • 15,864
  • This is what I was looking for - how to split terminal & execute particular scripts - thanks! But I wouldn't like to execute it everytime like this. Is there a possibility to have more of those configs & open each depending on what I need? Let's say by adding parameter --config2 or --config1 ? – jirislav Nov 17 '14 at 15:33
  • You don't add more config files, you add sections to the config file. See Terdon's post, he explains it very well, in fact I learned this from his post on an earlier thread. – dotancohen Nov 17 '14 at 15:39
  • Oh, I see ... Thus I accepted his answer as most helpful. But thanks anyway. – jirislav Nov 17 '14 at 15:41
  • Good choice! I actually wanted to suggest to accept his answer as the information did come from his hard work! – dotancohen Nov 17 '14 at 15:43
2

Wrapper script for splitting Terminator terminal emulator https://github.com/AlekseyChudov/terminator-split

  • 2
    You should include the relevant information here, once github is gone your answer loses all of its potential value. – Anthon Dec 24 '16 at 14:24
  • 1
    seems good.. but how do I run this script? – Sachin Aug 29 '18 at 21:24
  • 1
    terminator-split has a lot of potential, but there seems to be no way to run different commands in the different splits, and the -m argument shown in the examples is not listed in the usage summary – bitinerant Jul 24 '19 at 11:58