remi / teamocil

There's no I in Teamocil. At least not where you think. Teamocil is a simple tool used to automatically create windows and panes in tmux with YAML files.
MIT License
2.36k stars 101 forks source link

focus: true not switching to correct window // pane? #52

Closed thewatts closed 10 years ago

thewatts commented 10 years ago

Here is my current template,

running as: teamocil rails --here

session:
  name: "rails"
  windows:
    - name: "CODE"
      layout: 8590,178x45,0,0{114x45,0,0,3,63x45,115,0,4}
      panes:
        - cmd: "vim"
          focus: true
        - cmd: "guard"
    - name: "SERVER"
      layout: even-horizontal
      panes:
        - cmd: rails s -p 3000
        - cmd: ""

It won't switch to the "vim" pane inside of "CODE", instead it stays in the "SERVER" window.

Am I doing something wrong?

toobulkeh commented 10 years ago

:+1: for this issue.

Cyborg572 commented 10 years ago

I'm having this problem too. There's no problem focusing a pane as long as it's in the last window, but there's no way to switch to a specific window after initialization.

Cyborg572 commented 10 years ago

Oh, never mind. It looks like #53 added the focus option for windows. @toobulkeh Try updating the gem, that worked for me.

remi commented 10 years ago

@thewatts Can you test it with teamocil 1.0 please? Thanks!

johnhampton commented 10 years ago

Focus isn't working correctly in 1.0.3. In the below example I would expect the last select-window statement to choose window 2.

windows:
  - name: window-1
    focus: true
    root: /
    panes:
      - ls
  - name: window-2
    root: /
    panes:
      - ls
Deep-Thought:~ $ tmux list-windows
0: bash* (1 panes) [242x80] [layout b49d,242x80,0,0,0] @0 (active)
1: bash- (1 panes) [234x62] [layout b95e,234x62,0,0,1] @1

Deep-Thought:~ $ teamocil --debug test
tmux rename-session 'teamocil-session-506052'
tmux new-window -n 'window-1' -c '/'
tmux send-keys -t 0 'ls'
tmux send-keys -t 0 'Enter'
tmux select-layout ''
tmux select-pane -t 0
tmux new-window -n 'window-2' -c '/'
tmux send-keys -t 0 'ls'
tmux send-keys -t 0 'Enter'
tmux select-layout ''
tmux select-pane -t 0
tmux select-window -t 0
thewatts commented 10 years ago

@remiprev --- I posted a response days ago... but it must not have gone through.

I'll repost here in the next day or so.

Sorry about that!

remi commented 10 years ago

The first window (index 0) in the YAML file has the focus: true option. Therefore, tmux select-window -t 0 is sent by teamocil — I don’t see what’s wrong with that.

In the below example I would expect the last select-window statement to choose window 2.

Why?

johnhampton commented 10 years ago

Because there are already existing windows 0 and 1, so the first window teamocil creates is at index 2. Since teamocil is run within tmux, there is always at least 1 existing window.

remi commented 10 years ago

Oh, yes, you’re right. I never use teamocil with multiple window layout so I never tested this.

I just pushed a fix on master — could you test it?

This is also where I should be starting to rewrite the whole test suite :smile:

johnhampton commented 10 years ago

It didn't work for me, I got the following error.

Deep-Thought:~/Projects/3rdparty/teamocil (master) $ tmux ls
teamocil-session-147586: 1 windows (created Thu Aug 21 10:23:32 2014) [204x51] (attached)
Deep-Thought:~/Projects/3rdparty/teamocil (master) $ teamocil --show test
windows:
  - name: window-1
    root: "~"
    focus: true
    panes:
      - ls
  - name: window-2
    root: "~"
    panes:
      - ls
Deep-Thought:~/Projects/3rdparty/teamocil (master) $ teamocil test
/Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/tmux/window.rb:48:in `internal_index': undefined method `window_base_index' for Teamocil::Tmux::Window:Class (NoMethodError)
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/tmux/session.rb:25:in `block in as_tmux'
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/tmux/session.rb:19:in `tap'
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/tmux/session.rb:19:in `as_tmux'
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/layout.rb:37:in `shell_commands'
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/layout.rb:7:in `execute!'
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/lib/teamocil/cli.rb:21:in `run!'
        from /Users/john/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/teamocil-1.0.5/bin/teamocil:7:in `<top (required)>'
        from /Users/john/.rbenv/versions/2.0.0-p451/bin/teamocil:23:in `load'
        from /Users/john/.rbenv/versions/2.0.0-p451/bin/teamocil:23:in `<main>'
remi commented 10 years ago

Oops sorry, it should work now.

remi commented 10 years ago

@thewatts @johnhampton I’m going to close the issue as I believe the issue is now fixed. Feel free to reopen if it’s still not working for you!