The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

bash script to start several terminal/ssh windows with specific layout?

asked Nov 12 '14

bsmr gravatar image

updated Jul 28 '15

i3convert gravatar image

I need a bash script to start serveral terminals with ssh connections using a specific layout on demand, not at startup.

Basically each window (Wx) is a 'gnome-terminal -e "ssh $USER@$IPx"'. The layout I need is something like is:

+----+----+----+
| W1 |    |    |
+----+ W4 |    |
| W2 |----| W6 |
+----+ W5 |    |
| W3 |    |    |
+----+----+----+

I tried to use "i3-msg" to change the layout, and to move the terminals to different containers, but somehow I couldn't manage to get the layout I want.

Can someone give me some hints with this problem, please?

2 answers

Sort by » oldest newest most voted
0

answered Nov 12 '14

Adaephon gravatar image

The fastest and easiest way is to save the intended layout and restore it when needed on a fresh workspace. (Since version 4.8 i3 can save and restore layouts (see here)

Luckily with gnome-terminal you can set the window role with a command line parameter: --role ROLE, which makes it quite easy to assign specific positions for specific windows.

To start your terminals you can just use the following script and run it on an empty workspace:

#!/bin/bash
WS_LAYOUT_FILE=/some/where/layout
declare -A IPs
IPs=(
  [W1]=xx.xx.xx.01 
  [W2]=xx.xx.xx.02
  [W3]=xx.xx.xx.03
  [W4]=xx.xx.xx.04
  [W5]=xx.xx.xx.05
  [W6]=xx.xx.xx.06
)
SSH_USER=username

i3-msg append_layout "$WS_LAYOUT_FILE"

for window in ${!IPs[*]};
do
  gnome-terminal --role "$window" -e "ssh $SSH_USER@${IPs[$window)}" &
done

The layout file (/some/where/layout in the example) for your case looks like this:

{
  "border": "normal", "floating": "auto_off", 
  "layout": "splith", "type": "workspace",
  "nodes": [
    {
      "border": "normal", "floating": "auto_off", 
      "layout": "splitv", "percent": 0.333333333333333, "type": "con",
      "nodes": [
        {
          "border": "normal", "floating": "auto_off", 
          "layout": "splitv", "percent": 1, "type": "con",
          "nodes": [
            {
              "border": "normal", "floating": "auto_off", 
              "type": "con", "percent": 0.333333333333333,
              "name": "W1",
              "swallows": [ { "window_role": "^W1$" } ]
            },
            {
              "border": "normal", "floating": "auto_off", 
              "type": "con", "percent": 0.333333333333333,
              "name": "W2",
              "swallows": [ { "window_role": "^W2$" } ]
            },
            {
              "border": "normal", "floating": "auto_off", 
              "type": "con", "percent": 0.333333333333333,
              "name": "W3",
              "swallows": [ { "window_role": "^W3$" } ]
            }
          ]
        }
      ]
    },

    {
      "border": "normal", "floating": "auto_off", 
      "layout": "splitv", "percent": 0.333333333333333, "type": "con",
      "nodes": [
        {
          "border": "normal", "floating": "auto_off", 
          "type": "con", "percent": 0.5,
          "name": "W4",
          "swallows": [ { "window_role": "^W4$" } ]
        },
        {
          "border": "normal", "floating": "auto_off", 
          "type": "con", "percent": 0.5,
          "name": "W5",
          "swallows": [ { "window_role": "^W5$" } ]
        }
      ]
    },

    {
      "border": "normal", "floating": "auto_off", 
      "layout": "splitv", "percent": 0.333333333333333, "type": "con",
      "nodes": [
        {
          "border": "normal", "floating": "auto_off", 
          "type": "con", "percent": 1,
          "name": "W6",
          "swallows": [ { "window_role": "^W6$" } ]
        }
      ]
    }
  ]
}

append_layout opens placeholder windows as defined in the layout file. If a window is created that matches the rules in swallow (in this example only window_role is checked) i3 puts it in place of the placeholder.

0

answered Nov 13 '14

Leadguit gravatar image

updated Nov 13 '14

Since you're using Terminal-only, I would recommend terminator for such a setup.

You can define layouts, save them and define a "start command" for each terminal.

Short "Tutorial" for usage of terminator:

http:// blog.al4.co.nz/2011/05/getting-the-most-out-of-terminator/

Edit: Cannot post links due to having not enough karma

Comments

I haven't logged into here for quite some time, so I didn't see Your answer earlier. I had a brief look at ```terminator```, and actually I was not too happy. I still use the layout feature. But I will have a better look at ```terminator``` soon.

bsmr gravatar imagebsmr (Dec 4 '15)edit

Question Tools

Stats

Asked: Nov 12 '14

Seen: 3,742 times

Last updated: Nov 13 '14