tmuxtmuxinator

Using tmuxinator to open a dynamic number of windows


I would like to set up a tmuxinator project to open a dynamic number of tmux windows. In my scenario I would like one window per instance in an AWS Auto Scale Group.

I have a bash function to list the private IP of each server I want to attach to. For example:

$ prod-ips
10.X.X.1
10.X.X.2
10.X.X.3
10.X.X.4

I have a bash function to tunnel to any of those IPs:

$tunnel_to 10.X.X.1
....
works
ec2-user@10.x.x.1 ~ $

How do I pass the IP list returned from prod-ips into a tmuxinator project so that it will open 1 window for each line of output ?

Thanks!


Solution

  • Since project files are first processed as ERB, you could do something like the following:

    # ~/.tmuxinator/dyn.yml
    
    name: dyn
    root: ~/
    windows:
      # just using `echo` as a POC; this is where you'd make your function call
      <%- `echo "111,222,333"`.split(',').each do |ip| %>
      - tunnel-to-<%= ip.chomp %>: echo tunnel_to <%= ip %>
      <%- end %>