Spawn new Terminator tabs from Bash script
First, open a terminator instance, split it into 4 panes as desired and save as a new layout (make sure to close all open terminal windows except the one you've set up with your new profile). For each of the 4 panes, add a custom command but just add the text COMMAND1
, COMMAND2
etc. Save the new layout as foo
(or whatever). At this point, your ~/.config/terminator/config
should look something like this:
[global_config]
enabled_plugins = LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
focus = mouse
suppress_multiple_term_dialog = True
title_use_system_font = False
[keybindings]
[layouts]
[[default]]
[[[child0]]]
fullscreen = False
last_active_term = ad14f6cd-bcc3-4a80-9852-3fe64f7fc2eb
last_active_window = True
maximised = False
order = 0
parent = ""
size = 735, 474
title = sometitle
type = Window
[[foo]]
[[[child0]]]
fullscreen = False
last_active_term = 18ebf009-c427-4c2f-8017-78c379a72d31
last_active_window = True
maximised = False
order = 0
parent = ""
position = 2730:254
size = 735, 474
title = NAME-1
type = Window
[[[child1]]]
order = 0
parent = child0
position = 237
ratio = 0.5
type = VPaned
[[[child2]]]
order = 0
parent = child1
position = 368
ratio = 0.500680272109
type = HPaned
[[[child5]]]
order = 1
parent = child1
position = 368
ratio = 0.500680272109
type = HPaned
[[[terminal3]]]
command = COMMAND1
order = 0
parent = child2
profile = default
title = NAME-1
type = Terminal
uuid = 01e46a5a-0a12-4861-a81e-e376af6041a7
[[[terminal4]]]
command = COMMAND2
order = 1
parent = child2
profile = default
type = Terminal
uuid = 094d544d-944c-48a7-9960-00370253e799
[[[terminal6]]]
command = COMMAND3
order = 0
parent = child5
profile = default
type = Terminal
uuid = fe19f601-1963-4af7-8870-f90e289d3d27
[[[terminal7]]]
command = COMMAND4
order = 1
parent = child5
profile = default
type = Terminal
uuid = 18ebf009-c427-4c2f-8017-78c379a72d31
[plugins]
[profiles]
[[default]]
cursor_color = "#aaaaaa"
font = Monaco 11
scrollback_infinite = True
scrollback_lines = 5000
use_system_font = False
Now, modify your bash script to replace COMMANDN
with the actual command you need to run:
#!/bin/bash
## change these to whatever you actually need
command1="echo one; bash"
command2="echo two; bash"
command3="tail -f /var/log/messages; bash"
command4="top"
## Modify terminator's config
sed -i.bak "s#COMMAND1#$command1#; s#COMMAND2#$command2#; s#COMMAND3#$command3#; s#COMMAND4#$command4#;" ~/.config/terminator/config
## Launch a terminator instance using the new layout
terminator -l foo
## Return the original config file
mv ~/.config/terminator/config.bak ~/.config/terminator/config
Running that script will now open a new terminal window with 4 panes, each running one of your commands.
Important: if the command is something that runs and then exits (as opposed to something like top
which runs until you tell it to stop), you need COMMAN; bash
as the command so that a new shell will be started. Otherwise, the command will run and the shell will exit immediately. That's why I have ; bash
after each command except top
in y script.
Alternative:
Since you've mentioned that you'd accept alternative solution, consider using gnome-terminal
. In the past I've written scripts for that, which allow spawning window with multiple tabs and running their own commands. Please see this for example: https://askubuntu.com/a/863179/295286
As for terminator itself, it seems like it allows spawning new tabs for already existing window via --new-tab
option, but I see no option to spawn multi-tab window with individual commands other than via --layout
option. You can automate it, of course, since layouts are all go into ~/.config/terminator/config
file, so you could write out custom config file. I'll try to write one if I won't forget, but I think gnome-terminal
approach is far simpler and is exactly what you want.
Original answer
Terminator has a layout
preference, which you can use with specific number of tabs, splits, and assign specific color profiles to them. What you want to do is to open window , add how ever many tabs you want, and then right-click, go to Preferences , layouts tab, and click add button
Once you're done editing layout, save it. Now you can call use terminator -l <Layout Name>
to spawn window with that exact set of tabs. For instance, from my screenshot you can see I have custom
layout, so I would use terminator -l custom