Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: auto-generate layout file from currently running tmux session #32

Closed
gardiner opened this issue Oct 17, 2012 · 12 comments
Closed

Comments

@gardiner
Copy link

Just like "pip freeze" - freezes the currently visible tmux layout into a layout file skeleton. Would greatly simplify layout setup...

Anyway - teamocil is a great tool, don't want to miss it :) Thanks!

@remi
Copy link
Owner

remi commented Oct 17, 2012

I’ve been thinking about this for quite some times now, this is a feature I would also like to see.

The way I see it, a teamocil file is made from two main things: layout and commands.

Layout

I just added support for a layout option that you can user in window settings. Whatever you put in the layout option will be used in a tmux select-layout command, so you can use all of its supported values, like tiled, even-horizontal, main-vertical, etc. You can also use a custom tmux serialized layout, like bf75,203x51,0,0[204x25,0,0{76x25,0,0,58,127x25,77,0,59},204x25,0,26,60] which you can obtain by running this command in a window:

tmux list-windows -F "#{window_active} #{window_layout}" | grep "^1" | cut -d " " -f 2
Commands

As far as I’m aware, I don’t think it’s possible to extract the currently running command in each split. But I think the hardest part of building a teamocil layout is the actual splits layout.

So what I suggest is you manually build your layout, run the command above to extract its layout serialized string. You’ll then have something like this:

windows:
  - name: my new layout
    layout: "23f9,204x51,0,0{102x51,0,0,81,101x51,103,0[101x25,103,0,82,101x25,103,26{50x25,103,26,83,50x25,154,26,84}]}"

After that, you just have to create your splits array:

windows:
  - name: my new layout
    layout: "23f9,204x51,0,0{102x51,0,0,81,101x51,103,0[101x25,103,0,82,101x25,103,26{50x25,103,26,83,50x25,154,26,84}]}"
    splits:
      - cmd:
        - echo first
      - cmd:
        - echo second'
      - cmd:
        - echo third'
      - cmd:
        - echo fourth'

Hope that helps!

@gardiner
Copy link
Author

Wow, cool! I've got to try this. Thanks for the suggestion!

Now that I'm thinking about it, it should be relatively easy to get the current working directory (for the "root" option). And maybe one can inspect the shell history for the latest command? Unfortunately I don't know much ruby, otherwise I'd try to create some kind of teamocil command for that task. I'll probably try a shell script first.

@gardiner
Copy link
Author

Well, history does not work.
This on the other hand looks awful but seems to work: https://gist.github.com/3907932 ... It inspects the process list to find the last child process of each pane and then extracts the respective command. I guess someone who knows what he's doing should take a look at this instead ;)

@gardiner
Copy link
Author

There are some issues with this approach. For starters, the order of panes in the layout string is apparently not the same as the order of panes as returned by the list-panes command. That's why the commands end up in the wrong pane. Not dramatic, but not nice. No idea so far how to fix this.

@remi
Copy link
Owner

remi commented Oct 17, 2012

For starters, the order of panes in the layout string is apparently not the same as the order of panes as returned by the list-panes command. That's why the commands end up in the wrong pane. Not dramatic, but not nice.

Yeah, I actually thought this would be an issue, but I figured it would be much simpler to move the commands around in the YAML file than trying to parse tmux layout string :)

@gardiner
Copy link
Author

Oh yes :)

@gardiner
Copy link
Author

Aaaaaand there is another issue. Apparently the layout strings are not compatible across tmux versions. Too bad.

@remi
Copy link
Owner

remi commented Mar 21, 2013

I’m going to close this issue now since I’ve added the layout key for windows. Extracting commands seems a bit unnecessary 😄

@remi remi closed this as completed Mar 21, 2013
@scientist1642
Copy link

Hi @remiprev,
Your comment about getting current layout from terminal is super helpful!
What do you think mentioning this trick in the README? as I think MANY people would like to have custom layout (saying that we can use tmux splitting and :resize-pane commands as we like and then save the custom layout)

@remi
Copy link
Owner

remi commented Oct 9, 2016

@scientist1642 Yeah, I think it was in the README.md before the 1.0 rewrite. I’ll add it back 😄

@remi
Copy link
Owner

remi commented Oct 9, 2016

@scientist1642 Done! 7f8a47f

@scientist1642
Copy link

@remiprev cool! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants