linux - Start tmux session with only one window but several panes

06
2014-04
  • foobarbaz

    I'm trying to configure tmux so it starts creating a new session with three panes.

    One big pane on the left und two small panes on the right side.

    I set

    set -g default-terminal "screen-256color"
    

    in my tmux.conf - which can be found here.

    I found a broken(?) solution for this:

    # tmux session
    rename-session foo
    selectp -t 0
    splitw -h -p 43 'ncmpcpp'
    selectp -t 1
    splitw -v -p 35 'ncmpcpp -s visualizer'
    selectp -t 0
    

    When using this, the first created pane, pane 0, has TERM=screen and not TERM=screen-256color. Both other panes, also new ones created, have TERM=screen-256color.

    Any solution to this, or any other way how to create a session with only one window and X panes?

  • Answers
  • frak

    I have found that configuring sets of windows and/or panes to be much easier when using Tmuxinator which can also run arbitrary commands in each of the panes as well. Hope this helps...


  • Related Question

    Bash scripts with tmux to launch a 4-paned window
  • Aaron Gibralter

    Can anyone help explain what's going on with tmux, bash, and exec? I'm trying to set up a tmux session with a 4-pane window. Ideally, I want to run a command in 3 of the panes: e.g. a Ruby Thin server and a couple of Ruby daemons. This is what I have so far:

    ~/.bin/tmux-foo:

    #!/bin/sh
    
    tmux new-session -d -s foo 'exec pfoo "bundle exec thin start"'
    tmux rename-window 'Foo'
    tmux select-window -t foo:0
    tmux split-window -h 'exec pfoo "bundle exec compass watch"'
    tmux split-window -v -t 0 'exec pfoo "rake ts:start"'
    tmux split-window -v -t 1 'exec pfoo'
    tmux -2 attach-session -t foo
    

    ~/.bin/pfoo:

    #!/bin/bash
    cd ~/projects/foo
    rvm use ree
    
    # here I want to execute command1 2 3 or 4...
    
    exec $SHELL
    

    It all works... but when I ctlr-c in the first pane that is running the thin server, it stops the thin server and returns to the shell. However, the command is not in the history; i.e. if I hit the up key I don't get the bundle exec thin start command... I get some other command from my bash history. I'm wondering if there's any way to arrange these scripts so that I get the commands in the bash history.

    Also... I've tried many combinations of exec, exec $SHELL -s ..., and exec $SHELL -s ... -I and I'm not quite sure what is going on...

    Can anyone help explain the general idea of what is going on with tmux and bash and exec here?


  • Related Answers
  • grawity

    The commands are not in the shell's history simply because you started the shell after running those commands. Ctrl-C doesn't return to a shell; it causes pfoo to start a new one (the exec $SHELL line).

  • Aaron Gibralter

    It turns out that I wanted something like this:

    tmux splitw -t 'foo':2
    tmux send-keys -t 'foo':2 'rvm use ree' C-m
    tmux send-keys -t 'foo':2 'bundle exec compass watch
    

    send-keys with C-m will execute the command in the window/pane and will keep it in the history.