How do I create a simple tmux conf that splits a window?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
3












I'd like to create a simple tmux conf that does the follow.



  1. Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)

  2. Opens in the top pane tail -f foo

  3. Opens in the bottom pane tail -f bar

How can I do this with tmux.



This is what I've got,



#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf


I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever










share|improve this question





















  • Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
    – jasonwryan
    Aug 11 '14 at 20:39










  • @jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
    – Evan Carroll
    Aug 11 '14 at 20:48














up vote
4
down vote

favorite
3












I'd like to create a simple tmux conf that does the follow.



  1. Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)

  2. Opens in the top pane tail -f foo

  3. Opens in the bottom pane tail -f bar

How can I do this with tmux.



This is what I've got,



#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf


I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever










share|improve this question





















  • Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
    – jasonwryan
    Aug 11 '14 at 20:39










  • @jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
    – Evan Carroll
    Aug 11 '14 at 20:48












up vote
4
down vote

favorite
3









up vote
4
down vote

favorite
3






3





I'd like to create a simple tmux conf that does the follow.



  1. Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)

  2. Opens in the top pane tail -f foo

  3. Opens in the bottom pane tail -f bar

How can I do this with tmux.



This is what I've got,



#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf


I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever










share|improve this question













I'd like to create a simple tmux conf that does the follow.



  1. Splits the window/pane/whatever_stupid_terminology horizontally (hsplit)

  2. Opens in the top pane tail -f foo

  3. Opens in the bottom pane tail -f bar

How can I do this with tmux.



This is what I've got,



#!/bin/sh
tmux new-session -s asdf -n myWindow
tmux select-window -t myWindow
tmux split-window "tail -f /var/log/apache2/samperror.log"
tmux attach-session -t asdf


I can't get anything thought to work. So I know it's all wrong. One of the most unintuitive conf files ever







tmux






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 11 '14 at 6:10









Evan Carroll

4,69493775




4,69493775











  • Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
    – jasonwryan
    Aug 11 '14 at 20:39










  • @jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
    – Evan Carroll
    Aug 11 '14 at 20:48
















  • Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
    – jasonwryan
    Aug 11 '14 at 20:39










  • @jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
    – Evan Carroll
    Aug 11 '14 at 20:48















Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
– jasonwryan
Aug 11 '14 at 20:39




Your question refers to a tmux configuration file but your example is a standalone shell script; what approach are you actually interested in?
– jasonwryan
Aug 11 '14 at 20:39












@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
– Evan Carroll
Aug 11 '14 at 20:48




@jasonwryan thanks for that. I was desperate and I switched from a plain conf file -- which is what I'd prefer.
– Evan Carroll
Aug 11 '14 at 20:48










4 Answers
4






active

oldest

votes

















up vote
6
down vote













Here's a quick and dirty command-line that achieves what you want:



$ tmux new-session -s asdf -n myWindow -d 'tail -f foo'; 
split-window -d 'tail -f bar'; attach-session


There are a few drawbacks to this solution:



  • it doesn't scale very well (a few more commands and the result is incomprehensible).


  • the two tail commands aren't run in an interactive shell, so if you exit them both, the window myWindow will be destroyed (together with the session if you haven't created any more sessions.



Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:



#!/bin/sh
# create a new session. Note the -d flag, we do not want to attach just yet!
tmux new-session -s asdf -n 'myWindow' -d

# send 'tail -f foo<enter>' to the first pane.
# I address the first pane using the -t flag. This is not necessary,
# I'm doing it so explicitly to show you how to do it.
# for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j

# split the window *vertically*
tmux split-window -v

# we now have two panes in myWindow: pane 0 is above pane 1
# again, specifying pane 1 with '-t 1' is optional
tmux send-keys -t 1 'tail -f bar' C-j

# uncomment the following command if you want to attach
# explicitly to the window we just created

#tmux select-window -t asdf:mywindow

# finally attach to the session
tmux attach -t asdf


If after some trying you still don't like the tmux command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.




In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux resources






share|improve this answer





























    up vote
    1
    down vote













    Based on the answer here is more generic code:



    tmuxMany()
    #https://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
    echo usage: sessionName command1 command2 ...
    return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "$@:3" )

    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "$!secondAndRestCommands[@]"
    do
    echo $i
    local command=$secondAndRestCommands[$i]
    echo $command

    tmux split-window -v
    local tabNumber=$((i+1))
    tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux select-layout even-vertical
    tmux attach -t $sessionName



    Usage:



    tmuxMany sessionName "tail -f file" "tail -f file2" htop


    Will open tmux with 3 panes of equal height.






    share|improve this answer





























      up vote
      0
      down vote













      Assuming you do want to run this from your ~/.tmux.conf, not an external script, you would append this to your config file:



      # session initialisation
      new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
      splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
      selectw -t 0


      Then, when you start tmux with the command to attach to a session, tmux a, it will create SessionName with the window split horizontally (-h) in half (-p 50) running those two commands.






      share|improve this answer




















      • is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
        – Evan Carroll
        Aug 13 '14 at 1:11










      • @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
        – jasonwryan
        Aug 13 '14 at 1:19










      • So there is no way to do it from within the .conf file?
        – Evan Carroll
        Aug 13 '14 at 1:32






      • 1




        @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
        – jasonwryan
        Aug 13 '14 at 1:39

















      up vote
      0
      down vote













      This is how I launch an editor + REPL now:



      mux $(basename $(pwd)) 
      "vim $(find src test resources test-resources -type f 2>/dev/null
      | tr "n" " ")"
      "lein repl"


      I hacked on Maxim's code to get a different layout:



      #!/bin/bash

      #https://unix.stackexchange.com/a/149729/47116
      if [ $# -lt 2 ]; then
      echo usage: sessionName command1 command2 ...
      return 1
      fi
      sessionName=$1
      firstCommand=$2
      secondAndRestCommands=( "$@:3" )

      tmux new-session -s $sessionName -n 'myWindow' -d
      WIN="$sessionName:myWindow"
      tmux send-keys -t $WIN.1 "$firstCommand" C-j
      for i in "$!secondAndRestCommands[@]"
      do
      command=$secondAndRestCommands[$i]
      echo $i: $command

      tmux split-window -v
      tabNumber=$((i+2))
      tmux send-keys -t $tabNumber "$command" C-j
      done
      tmux select-pane -t $WIN.1

      fixlayout()
      tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
      tmux select-layout -t $WIN main-vertical

      fixlayout
      sleep 1 && fixlayout &

      tmux attach -t $sessionName


      Incidentally this guy's tmux.conf seems pretty useful.






      share|improve this answer








      New contributor




      lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f149606%2fhow-do-i-create-a-simple-tmux-conf-that-splits-a-window%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        6
        down vote













        Here's a quick and dirty command-line that achieves what you want:



        $ tmux new-session -s asdf -n myWindow -d 'tail -f foo'; 
        split-window -d 'tail -f bar'; attach-session


        There are a few drawbacks to this solution:



        • it doesn't scale very well (a few more commands and the result is incomprehensible).


        • the two tail commands aren't run in an interactive shell, so if you exit them both, the window myWindow will be destroyed (together with the session if you haven't created any more sessions.



        Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:



        #!/bin/sh
        # create a new session. Note the -d flag, we do not want to attach just yet!
        tmux new-session -s asdf -n 'myWindow' -d

        # send 'tail -f foo<enter>' to the first pane.
        # I address the first pane using the -t flag. This is not necessary,
        # I'm doing it so explicitly to show you how to do it.
        # for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
        tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j

        # split the window *vertically*
        tmux split-window -v

        # we now have two panes in myWindow: pane 0 is above pane 1
        # again, specifying pane 1 with '-t 1' is optional
        tmux send-keys -t 1 'tail -f bar' C-j

        # uncomment the following command if you want to attach
        # explicitly to the window we just created

        #tmux select-window -t asdf:mywindow

        # finally attach to the session
        tmux attach -t asdf


        If after some trying you still don't like the tmux command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.




        In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux resources






        share|improve this answer


























          up vote
          6
          down vote













          Here's a quick and dirty command-line that achieves what you want:



          $ tmux new-session -s asdf -n myWindow -d 'tail -f foo'; 
          split-window -d 'tail -f bar'; attach-session


          There are a few drawbacks to this solution:



          • it doesn't scale very well (a few more commands and the result is incomprehensible).


          • the two tail commands aren't run in an interactive shell, so if you exit them both, the window myWindow will be destroyed (together with the session if you haven't created any more sessions.



          Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:



          #!/bin/sh
          # create a new session. Note the -d flag, we do not want to attach just yet!
          tmux new-session -s asdf -n 'myWindow' -d

          # send 'tail -f foo<enter>' to the first pane.
          # I address the first pane using the -t flag. This is not necessary,
          # I'm doing it so explicitly to show you how to do it.
          # for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
          tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j

          # split the window *vertically*
          tmux split-window -v

          # we now have two panes in myWindow: pane 0 is above pane 1
          # again, specifying pane 1 with '-t 1' is optional
          tmux send-keys -t 1 'tail -f bar' C-j

          # uncomment the following command if you want to attach
          # explicitly to the window we just created

          #tmux select-window -t asdf:mywindow

          # finally attach to the session
          tmux attach -t asdf


          If after some trying you still don't like the tmux command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.




          In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux resources






          share|improve this answer
























            up vote
            6
            down vote










            up vote
            6
            down vote









            Here's a quick and dirty command-line that achieves what you want:



            $ tmux new-session -s asdf -n myWindow -d 'tail -f foo'; 
            split-window -d 'tail -f bar'; attach-session


            There are a few drawbacks to this solution:



            • it doesn't scale very well (a few more commands and the result is incomprehensible).


            • the two tail commands aren't run in an interactive shell, so if you exit them both, the window myWindow will be destroyed (together with the session if you haven't created any more sessions.



            Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:



            #!/bin/sh
            # create a new session. Note the -d flag, we do not want to attach just yet!
            tmux new-session -s asdf -n 'myWindow' -d

            # send 'tail -f foo<enter>' to the first pane.
            # I address the first pane using the -t flag. This is not necessary,
            # I'm doing it so explicitly to show you how to do it.
            # for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
            tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j

            # split the window *vertically*
            tmux split-window -v

            # we now have two panes in myWindow: pane 0 is above pane 1
            # again, specifying pane 1 with '-t 1' is optional
            tmux send-keys -t 1 'tail -f bar' C-j

            # uncomment the following command if you want to attach
            # explicitly to the window we just created

            #tmux select-window -t asdf:mywindow

            # finally attach to the session
            tmux attach -t asdf


            If after some trying you still don't like the tmux command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.




            In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux resources






            share|improve this answer














            Here's a quick and dirty command-line that achieves what you want:



            $ tmux new-session -s asdf -n myWindow -d 'tail -f foo'; 
            split-window -d 'tail -f bar'; attach-session


            There are a few drawbacks to this solution:



            • it doesn't scale very well (a few more commands and the result is incomprehensible).


            • the two tail commands aren't run in an interactive shell, so if you exit them both, the window myWindow will be destroyed (together with the session if you haven't created any more sessions.



            Here's a shell script that works along the lines that you tried. For me it's always easiest to think about how I would achieve my goal manually and then translate that into tmux commands. This might not be the simplest or cleanest way, but it usually works:



            #!/bin/sh
            # create a new session. Note the -d flag, we do not want to attach just yet!
            tmux new-session -s asdf -n 'myWindow' -d

            # send 'tail -f foo<enter>' to the first pane.
            # I address the first pane using the -t flag. This is not necessary,
            # I'm doing it so explicitly to show you how to do it.
            # for the <enter> key, we can use either C-m (linefeed) or C-j (newline)
            tmux send-keys -t asdf:myWindow.0 'tail -f foo' C-j

            # split the window *vertically*
            tmux split-window -v

            # we now have two panes in myWindow: pane 0 is above pane 1
            # again, specifying pane 1 with '-t 1' is optional
            tmux send-keys -t 1 'tail -f bar' C-j

            # uncomment the following command if you want to attach
            # explicitly to the window we just created

            #tmux select-window -t asdf:mywindow

            # finally attach to the session
            tmux attach -t asdf


            If after some trying you still don't like the tmux command and configuration syntax, you might want to look into tmuxinator, a Ruby gem that lets you manage tmux sessions with a simplified and more transparent syntax.




            In my answer to Multiple terminals at once without an X server you can find a few links to helpful tmux resources







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 2 at 23:20









            Jeff Schaller

            33.6k851113




            33.6k851113










            answered Aug 11 '14 at 17:13









            user80519

            613




            613






















                up vote
                1
                down vote













                Based on the answer here is more generic code:



                tmuxMany()
                #https://unix.stackexchange.com/a/149729/47116
                if [ $# -lt 2 ]; then
                echo usage: sessionName command1 command2 ...
                return 1
                fi
                local sessionName=$1
                local firstCommand=$2
                local secondAndRestCommands=( "$@:3" )

                tmux new-session -s $sessionName -n 'myWindow' -d
                tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
                local i
                for i in "$!secondAndRestCommands[@]"
                do
                echo $i
                local command=$secondAndRestCommands[$i]
                echo $command

                tmux split-window -v
                local tabNumber=$((i+1))
                tmux send-keys -t $tabNumber "$command" C-j
                done
                tmux select-layout even-vertical
                tmux attach -t $sessionName



                Usage:



                tmuxMany sessionName "tail -f file" "tail -f file2" htop


                Will open tmux with 3 panes of equal height.






                share|improve this answer


























                  up vote
                  1
                  down vote













                  Based on the answer here is more generic code:



                  tmuxMany()
                  #https://unix.stackexchange.com/a/149729/47116
                  if [ $# -lt 2 ]; then
                  echo usage: sessionName command1 command2 ...
                  return 1
                  fi
                  local sessionName=$1
                  local firstCommand=$2
                  local secondAndRestCommands=( "$@:3" )

                  tmux new-session -s $sessionName -n 'myWindow' -d
                  tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
                  local i
                  for i in "$!secondAndRestCommands[@]"
                  do
                  echo $i
                  local command=$secondAndRestCommands[$i]
                  echo $command

                  tmux split-window -v
                  local tabNumber=$((i+1))
                  tmux send-keys -t $tabNumber "$command" C-j
                  done
                  tmux select-layout even-vertical
                  tmux attach -t $sessionName



                  Usage:



                  tmuxMany sessionName "tail -f file" "tail -f file2" htop


                  Will open tmux with 3 panes of equal height.






                  share|improve this answer
























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Based on the answer here is more generic code:



                    tmuxMany()
                    #https://unix.stackexchange.com/a/149729/47116
                    if [ $# -lt 2 ]; then
                    echo usage: sessionName command1 command2 ...
                    return 1
                    fi
                    local sessionName=$1
                    local firstCommand=$2
                    local secondAndRestCommands=( "$@:3" )

                    tmux new-session -s $sessionName -n 'myWindow' -d
                    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
                    local i
                    for i in "$!secondAndRestCommands[@]"
                    do
                    echo $i
                    local command=$secondAndRestCommands[$i]
                    echo $command

                    tmux split-window -v
                    local tabNumber=$((i+1))
                    tmux send-keys -t $tabNumber "$command" C-j
                    done
                    tmux select-layout even-vertical
                    tmux attach -t $sessionName



                    Usage:



                    tmuxMany sessionName "tail -f file" "tail -f file2" htop


                    Will open tmux with 3 panes of equal height.






                    share|improve this answer














                    Based on the answer here is more generic code:



                    tmuxMany()
                    #https://unix.stackexchange.com/a/149729/47116
                    if [ $# -lt 2 ]; then
                    echo usage: sessionName command1 command2 ...
                    return 1
                    fi
                    local sessionName=$1
                    local firstCommand=$2
                    local secondAndRestCommands=( "$@:3" )

                    tmux new-session -s $sessionName -n 'myWindow' -d
                    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
                    local i
                    for i in "$!secondAndRestCommands[@]"
                    do
                    echo $i
                    local command=$secondAndRestCommands[$i]
                    echo $command

                    tmux split-window -v
                    local tabNumber=$((i+1))
                    tmux send-keys -t $tabNumber "$command" C-j
                    done
                    tmux select-layout even-vertical
                    tmux attach -t $sessionName



                    Usage:



                    tmuxMany sessionName "tail -f file" "tail -f file2" htop


                    Will open tmux with 3 panes of equal height.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 13 '17 at 12:36









                    Community♦

                    1




                    1










                    answered Dec 23 '16 at 7:53









                    Maxim Yefremov

                    22338




                    22338




















                        up vote
                        0
                        down vote













                        Assuming you do want to run this from your ~/.tmux.conf, not an external script, you would append this to your config file:



                        # session initialisation
                        new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
                        splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
                        selectw -t 0


                        Then, when you start tmux with the command to attach to a session, tmux a, it will create SessionName with the window split horizontally (-h) in half (-p 50) running those two commands.






                        share|improve this answer




















                        • is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
                          – Evan Carroll
                          Aug 13 '14 at 1:11










                        • @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
                          – jasonwryan
                          Aug 13 '14 at 1:19










                        • So there is no way to do it from within the .conf file?
                          – Evan Carroll
                          Aug 13 '14 at 1:32






                        • 1




                          @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
                          – jasonwryan
                          Aug 13 '14 at 1:39














                        up vote
                        0
                        down vote













                        Assuming you do want to run this from your ~/.tmux.conf, not an external script, you would append this to your config file:



                        # session initialisation
                        new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
                        splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
                        selectw -t 0


                        Then, when you start tmux with the command to attach to a session, tmux a, it will create SessionName with the window split horizontally (-h) in half (-p 50) running those two commands.






                        share|improve this answer




















                        • is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
                          – Evan Carroll
                          Aug 13 '14 at 1:11










                        • @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
                          – jasonwryan
                          Aug 13 '14 at 1:19










                        • So there is no way to do it from within the .conf file?
                          – Evan Carroll
                          Aug 13 '14 at 1:32






                        • 1




                          @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
                          – jasonwryan
                          Aug 13 '14 at 1:39












                        up vote
                        0
                        down vote










                        up vote
                        0
                        down vote









                        Assuming you do want to run this from your ~/.tmux.conf, not an external script, you would append this to your config file:



                        # session initialisation
                        new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
                        splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
                        selectw -t 0


                        Then, when you start tmux with the command to attach to a session, tmux a, it will create SessionName with the window split horizontally (-h) in half (-p 50) running those two commands.






                        share|improve this answer












                        Assuming you do want to run this from your ~/.tmux.conf, not an external script, you would append this to your config file:



                        # session initialisation
                        new -s SessionName -n WindowName 'tail -f /var/log/apache2/samperror.log'
                        splitw -h -p 50 -t 0 'tail -f /var/log/apache2/other.log'
                        selectw -t 0


                        Then, when you start tmux with the command to attach to a session, tmux a, it will create SessionName with the window split horizontally (-h) in half (-p 50) running those two commands.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Aug 11 '14 at 21:11









                        jasonwryan

                        47.7k14131180




                        47.7k14131180











                        • is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
                          – Evan Carroll
                          Aug 13 '14 at 1:11










                        • @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
                          – jasonwryan
                          Aug 13 '14 at 1:19










                        • So there is no way to do it from within the .conf file?
                          – Evan Carroll
                          Aug 13 '14 at 1:32






                        • 1




                          @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
                          – jasonwryan
                          Aug 13 '14 at 1:39
















                        • is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
                          – Evan Carroll
                          Aug 13 '14 at 1:11










                        • @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
                          – jasonwryan
                          Aug 13 '14 at 1:19










                        • So there is no way to do it from within the .conf file?
                          – Evan Carroll
                          Aug 13 '14 at 1:32






                        • 1




                          @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
                          – jasonwryan
                          Aug 13 '14 at 1:39















                        is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
                        – Evan Carroll
                        Aug 13 '14 at 1:11




                        is there anyway to make the session automagically attach so I can just run tmux -f tmux.conf, and if the session already exists it attaches it -- otherwise it initializes and attaches?
                        – Evan Carroll
                        Aug 13 '14 at 1:11












                        @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
                        – jasonwryan
                        Aug 13 '14 at 1:19




                        @EvanCarroll That is what the a (a contraction of attach) is for. You can always write a function, like so: tmuxa() [[ -z "$TMUX" ]] && tmux -f $HOME/.tmux/conf new -s SessionName ;
                        – jasonwryan
                        Aug 13 '14 at 1:19












                        So there is no way to do it from within the .conf file?
                        – Evan Carroll
                        Aug 13 '14 at 1:32




                        So there is no way to do it from within the .conf file?
                        – Evan Carroll
                        Aug 13 '14 at 1:32




                        1




                        1




                        @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
                        – jasonwryan
                        Aug 13 '14 at 1:39




                        @EvanCarroll that wouldn't really make much sense; it would, among other things, prevent you from opening a separate tmux session.
                        – jasonwryan
                        Aug 13 '14 at 1:39










                        up vote
                        0
                        down vote













                        This is how I launch an editor + REPL now:



                        mux $(basename $(pwd)) 
                        "vim $(find src test resources test-resources -type f 2>/dev/null
                        | tr "n" " ")"
                        "lein repl"


                        I hacked on Maxim's code to get a different layout:



                        #!/bin/bash

                        #https://unix.stackexchange.com/a/149729/47116
                        if [ $# -lt 2 ]; then
                        echo usage: sessionName command1 command2 ...
                        return 1
                        fi
                        sessionName=$1
                        firstCommand=$2
                        secondAndRestCommands=( "$@:3" )

                        tmux new-session -s $sessionName -n 'myWindow' -d
                        WIN="$sessionName:myWindow"
                        tmux send-keys -t $WIN.1 "$firstCommand" C-j
                        for i in "$!secondAndRestCommands[@]"
                        do
                        command=$secondAndRestCommands[$i]
                        echo $i: $command

                        tmux split-window -v
                        tabNumber=$((i+2))
                        tmux send-keys -t $tabNumber "$command" C-j
                        done
                        tmux select-pane -t $WIN.1

                        fixlayout()
                        tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
                        tmux select-layout -t $WIN main-vertical

                        fixlayout
                        sleep 1 && fixlayout &

                        tmux attach -t $sessionName


                        Incidentally this guy's tmux.conf seems pretty useful.






                        share|improve this answer








                        New contributor




                        lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.





















                          up vote
                          0
                          down vote













                          This is how I launch an editor + REPL now:



                          mux $(basename $(pwd)) 
                          "vim $(find src test resources test-resources -type f 2>/dev/null
                          | tr "n" " ")"
                          "lein repl"


                          I hacked on Maxim's code to get a different layout:



                          #!/bin/bash

                          #https://unix.stackexchange.com/a/149729/47116
                          if [ $# -lt 2 ]; then
                          echo usage: sessionName command1 command2 ...
                          return 1
                          fi
                          sessionName=$1
                          firstCommand=$2
                          secondAndRestCommands=( "$@:3" )

                          tmux new-session -s $sessionName -n 'myWindow' -d
                          WIN="$sessionName:myWindow"
                          tmux send-keys -t $WIN.1 "$firstCommand" C-j
                          for i in "$!secondAndRestCommands[@]"
                          do
                          command=$secondAndRestCommands[$i]
                          echo $i: $command

                          tmux split-window -v
                          tabNumber=$((i+2))
                          tmux send-keys -t $tabNumber "$command" C-j
                          done
                          tmux select-pane -t $WIN.1

                          fixlayout()
                          tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
                          tmux select-layout -t $WIN main-vertical

                          fixlayout
                          sleep 1 && fixlayout &

                          tmux attach -t $sessionName


                          Incidentally this guy's tmux.conf seems pretty useful.






                          share|improve this answer








                          New contributor




                          lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.



















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            This is how I launch an editor + REPL now:



                            mux $(basename $(pwd)) 
                            "vim $(find src test resources test-resources -type f 2>/dev/null
                            | tr "n" " ")"
                            "lein repl"


                            I hacked on Maxim's code to get a different layout:



                            #!/bin/bash

                            #https://unix.stackexchange.com/a/149729/47116
                            if [ $# -lt 2 ]; then
                            echo usage: sessionName command1 command2 ...
                            return 1
                            fi
                            sessionName=$1
                            firstCommand=$2
                            secondAndRestCommands=( "$@:3" )

                            tmux new-session -s $sessionName -n 'myWindow' -d
                            WIN="$sessionName:myWindow"
                            tmux send-keys -t $WIN.1 "$firstCommand" C-j
                            for i in "$!secondAndRestCommands[@]"
                            do
                            command=$secondAndRestCommands[$i]
                            echo $i: $command

                            tmux split-window -v
                            tabNumber=$((i+2))
                            tmux send-keys -t $tabNumber "$command" C-j
                            done
                            tmux select-pane -t $WIN.1

                            fixlayout()
                            tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
                            tmux select-layout -t $WIN main-vertical

                            fixlayout
                            sleep 1 && fixlayout &

                            tmux attach -t $sessionName


                            Incidentally this guy's tmux.conf seems pretty useful.






                            share|improve this answer








                            New contributor




                            lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            This is how I launch an editor + REPL now:



                            mux $(basename $(pwd)) 
                            "vim $(find src test resources test-resources -type f 2>/dev/null
                            | tr "n" " ")"
                            "lein repl"


                            I hacked on Maxim's code to get a different layout:



                            #!/bin/bash

                            #https://unix.stackexchange.com/a/149729/47116
                            if [ $# -lt 2 ]; then
                            echo usage: sessionName command1 command2 ...
                            return 1
                            fi
                            sessionName=$1
                            firstCommand=$2
                            secondAndRestCommands=( "$@:3" )

                            tmux new-session -s $sessionName -n 'myWindow' -d
                            WIN="$sessionName:myWindow"
                            tmux send-keys -t $WIN.1 "$firstCommand" C-j
                            for i in "$!secondAndRestCommands[@]"
                            do
                            command=$secondAndRestCommands[$i]
                            echo $i: $command

                            tmux split-window -v
                            tabNumber=$((i+2))
                            tmux send-keys -t $tabNumber "$command" C-j
                            done
                            tmux select-pane -t $WIN.1

                            fixlayout()
                            tmux set-window-option -t $WIN main-pane-width $(($COLUMNS - 80))
                            tmux select-layout -t $WIN main-vertical

                            fixlayout
                            sleep 1 && fixlayout &

                            tmux attach -t $sessionName


                            Incidentally this guy's tmux.conf seems pretty useful.







                            share|improve this answer








                            New contributor




                            lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered Oct 1 at 8:07









                            lxs

                            1011




                            1011




                            New contributor




                            lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            lxs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f149606%2fhow-do-i-create-a-simple-tmux-conf-that-splits-a-window%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay