The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
1

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

asked 2014-11-12 09:14:01 +0000

bsmr gravatar image

updated 2015-07-28 05:09:56 +0000

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?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-11-12 12:45:36 +0000

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.

edit flag offensive delete link more
0

answered 2014-11-13 18:11:46 +0000

Leadguit gravatar image

updated 2014-11-13 18:13:49 +0000

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

edit flag offensive delete link more

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 ( 2015-12-04 09:48:47 +0000 )edit

Question Tools

Stats

Asked: 2014-11-12 09:14:01 +0000

Seen: 3,742 times

Last updated: Nov 13 '14