TMUX: After split-window, how do I know the new pane id?

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











up vote
1
down vote

favorite












It seems like a simple enough procedure that I'm trying to accomplish, yet I've searched to no avail. I would like to create a key binding which does a split-window and then send-keys to the newly-created pane; however I need the pane id to use with the send-keys command. The catch is that I WILL NOT know how many panes are currently open in the window; thus I know of no way for the code running in the original pane to deduce what the new pane index will be. Is there any way to find out this new index or id (either one can be used as a target)?



Thanks.










share|improve this question

























    up vote
    1
    down vote

    favorite












    It seems like a simple enough procedure that I'm trying to accomplish, yet I've searched to no avail. I would like to create a key binding which does a split-window and then send-keys to the newly-created pane; however I need the pane id to use with the send-keys command. The catch is that I WILL NOT know how many panes are currently open in the window; thus I know of no way for the code running in the original pane to deduce what the new pane index will be. Is there any way to find out this new index or id (either one can be used as a target)?



    Thanks.










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      It seems like a simple enough procedure that I'm trying to accomplish, yet I've searched to no avail. I would like to create a key binding which does a split-window and then send-keys to the newly-created pane; however I need the pane id to use with the send-keys command. The catch is that I WILL NOT know how many panes are currently open in the window; thus I know of no way for the code running in the original pane to deduce what the new pane index will be. Is there any way to find out this new index or id (either one can be used as a target)?



      Thanks.










      share|improve this question













      It seems like a simple enough procedure that I'm trying to accomplish, yet I've searched to no avail. I would like to create a key binding which does a split-window and then send-keys to the newly-created pane; however I need the pane id to use with the send-keys command. The catch is that I WILL NOT know how many panes are currently open in the window; thus I know of no way for the code running in the original pane to deduce what the new pane index will be. Is there any way to find out this new index or id (either one can be used as a target)?



      Thanks.







      tmux






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 5 '17 at 20:14









      Kyndig

      285




      285




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You are over-thinking your problem. When you do split-window the new pane becomes the current target for send-keys. You should not be calling tmux in the binding as you are already in tmux. Try



          bind-key s split-window ; send-keys "pwd" Enter





          share|improve this answer




















          • That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
            – Kyndig
            Jul 10 '17 at 22:04










          • I have tmux version 2.1 (tmux -V)
            – meuh
            Jul 11 '17 at 7:45










          • 2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
            – Kyndig
            Jul 12 '17 at 17:11

















          up vote
          1
          down vote













          Well, I'd still prefer to find a direct way to get at the new pane ID, but I was at least able to accomplish my goal by calling a shell script instead of trying to do it all in the tmux.conf. Seems kludgy to me, but it works. tmux.conf:



          bind s run-shell "~/bin/tmux_split_pane.sh '#window_id' '#pane_id'"


          and the script:



          #!/bin/sh

          current_window_id=$1
          current_pane_id=$2

          tmux split-window -t $current_pane_id
          new_pane_id=$(tmux list-panes -F '#pane_id' -t "$current_window_id" | sort -n --key=1.2 | tail -1)
          tmux send-keys -t $new_pane_id -l "update_env" ; send-keys -t $new_pane_id Enter





          share|improve this answer





























            up vote
            0
            down vote













            In tmux, each new pane gets an unique value, which you can access using environment variable TMUX_PANE.
            tmux display -pt "$TMUX_PANE:?" '#pane_index'
            this will show pane number.






            share|improve this answer






















            • But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
              – Kyndig
              Jul 6 '17 at 18:59











            • Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
              – Kyndig
              Jul 6 '17 at 19:12

















            up vote
            0
            down vote













            I did it by sending the new pane's id back through a named pipe.



            mkfifo pane_id
            tmux split-window -h ; send-keys 'echo $TMUX_PANE > pane_id' Enter ; select-pane -t "$TMUX_PANE"
            cat pane_id





            share|improve this answer




















              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%2f375567%2ftmux-after-split-window-how-do-i-know-the-new-pane-id%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
              0
              down vote



              accepted










              You are over-thinking your problem. When you do split-window the new pane becomes the current target for send-keys. You should not be calling tmux in the binding as you are already in tmux. Try



              bind-key s split-window ; send-keys "pwd" Enter





              share|improve this answer




















              • That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
                – Kyndig
                Jul 10 '17 at 22:04










              • I have tmux version 2.1 (tmux -V)
                – meuh
                Jul 11 '17 at 7:45










              • 2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
                – Kyndig
                Jul 12 '17 at 17:11














              up vote
              0
              down vote



              accepted










              You are over-thinking your problem. When you do split-window the new pane becomes the current target for send-keys. You should not be calling tmux in the binding as you are already in tmux. Try



              bind-key s split-window ; send-keys "pwd" Enter





              share|improve this answer




















              • That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
                – Kyndig
                Jul 10 '17 at 22:04










              • I have tmux version 2.1 (tmux -V)
                – meuh
                Jul 11 '17 at 7:45










              • 2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
                – Kyndig
                Jul 12 '17 at 17:11












              up vote
              0
              down vote



              accepted







              up vote
              0
              down vote



              accepted






              You are over-thinking your problem. When you do split-window the new pane becomes the current target for send-keys. You should not be calling tmux in the binding as you are already in tmux. Try



              bind-key s split-window ; send-keys "pwd" Enter





              share|improve this answer












              You are over-thinking your problem. When you do split-window the new pane becomes the current target for send-keys. You should not be calling tmux in the binding as you are already in tmux. Try



              bind-key s split-window ; send-keys "pwd" Enter






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jul 8 '17 at 15:48









              meuh

              30.7k11754




              30.7k11754











              • That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
                – Kyndig
                Jul 10 '17 at 22:04










              • I have tmux version 2.1 (tmux -V)
                – meuh
                Jul 11 '17 at 7:45










              • 2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
                – Kyndig
                Jul 12 '17 at 17:11
















              • That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
                – Kyndig
                Jul 10 '17 at 22:04










              • I have tmux version 2.1 (tmux -V)
                – meuh
                Jul 11 '17 at 7:45










              • 2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
                – Kyndig
                Jul 12 '17 at 17:11















              That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
              – Kyndig
              Jul 10 '17 at 22:04




              That was the first thing I tried, actually, but the "pwd" was (and still is after trying again just now) printed in the original pane, not the new one; behaving as if I had given it the "-d" argument, but I did not... I used the exact same binding you have written above. Maybe there's something else about my setup (tmux.conf or plugins) that's changing the behavior to not switching the pane focus after creation?
              – Kyndig
              Jul 10 '17 at 22:04












              I have tmux version 2.1 (tmux -V)
              – meuh
              Jul 11 '17 at 7:45




              I have tmux version 2.1 (tmux -V)
              – meuh
              Jul 11 '17 at 7:45












              2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
              – Kyndig
              Jul 12 '17 at 17:11




              2.4 here. Does anyone have any ideas about how I can diagnose why split-window behaves as if I passed the -d argument when I haven't?
              – Kyndig
              Jul 12 '17 at 17:11












              up vote
              1
              down vote













              Well, I'd still prefer to find a direct way to get at the new pane ID, but I was at least able to accomplish my goal by calling a shell script instead of trying to do it all in the tmux.conf. Seems kludgy to me, but it works. tmux.conf:



              bind s run-shell "~/bin/tmux_split_pane.sh '#window_id' '#pane_id'"


              and the script:



              #!/bin/sh

              current_window_id=$1
              current_pane_id=$2

              tmux split-window -t $current_pane_id
              new_pane_id=$(tmux list-panes -F '#pane_id' -t "$current_window_id" | sort -n --key=1.2 | tail -1)
              tmux send-keys -t $new_pane_id -l "update_env" ; send-keys -t $new_pane_id Enter





              share|improve this answer


























                up vote
                1
                down vote













                Well, I'd still prefer to find a direct way to get at the new pane ID, but I was at least able to accomplish my goal by calling a shell script instead of trying to do it all in the tmux.conf. Seems kludgy to me, but it works. tmux.conf:



                bind s run-shell "~/bin/tmux_split_pane.sh '#window_id' '#pane_id'"


                and the script:



                #!/bin/sh

                current_window_id=$1
                current_pane_id=$2

                tmux split-window -t $current_pane_id
                new_pane_id=$(tmux list-panes -F '#pane_id' -t "$current_window_id" | sort -n --key=1.2 | tail -1)
                tmux send-keys -t $new_pane_id -l "update_env" ; send-keys -t $new_pane_id Enter





                share|improve this answer
























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Well, I'd still prefer to find a direct way to get at the new pane ID, but I was at least able to accomplish my goal by calling a shell script instead of trying to do it all in the tmux.conf. Seems kludgy to me, but it works. tmux.conf:



                  bind s run-shell "~/bin/tmux_split_pane.sh '#window_id' '#pane_id'"


                  and the script:



                  #!/bin/sh

                  current_window_id=$1
                  current_pane_id=$2

                  tmux split-window -t $current_pane_id
                  new_pane_id=$(tmux list-panes -F '#pane_id' -t "$current_window_id" | sort -n --key=1.2 | tail -1)
                  tmux send-keys -t $new_pane_id -l "update_env" ; send-keys -t $new_pane_id Enter





                  share|improve this answer














                  Well, I'd still prefer to find a direct way to get at the new pane ID, but I was at least able to accomplish my goal by calling a shell script instead of trying to do it all in the tmux.conf. Seems kludgy to me, but it works. tmux.conf:



                  bind s run-shell "~/bin/tmux_split_pane.sh '#window_id' '#pane_id'"


                  and the script:



                  #!/bin/sh

                  current_window_id=$1
                  current_pane_id=$2

                  tmux split-window -t $current_pane_id
                  new_pane_id=$(tmux list-panes -F '#pane_id' -t "$current_window_id" | sort -n --key=1.2 | tail -1)
                  tmux send-keys -t $new_pane_id -l "update_env" ; send-keys -t $new_pane_id Enter






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 12 mins ago

























                  answered Jul 7 '17 at 22:21









                  Kyndig

                  285




                  285




















                      up vote
                      0
                      down vote













                      In tmux, each new pane gets an unique value, which you can access using environment variable TMUX_PANE.
                      tmux display -pt "$TMUX_PANE:?" '#pane_index'
                      this will show pane number.






                      share|improve this answer






















                      • But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
                        – Kyndig
                        Jul 6 '17 at 18:59











                      • Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
                        – Kyndig
                        Jul 6 '17 at 19:12














                      up vote
                      0
                      down vote













                      In tmux, each new pane gets an unique value, which you can access using environment variable TMUX_PANE.
                      tmux display -pt "$TMUX_PANE:?" '#pane_index'
                      this will show pane number.






                      share|improve this answer






















                      • But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
                        – Kyndig
                        Jul 6 '17 at 18:59











                      • Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
                        – Kyndig
                        Jul 6 '17 at 19:12












                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      In tmux, each new pane gets an unique value, which you can access using environment variable TMUX_PANE.
                      tmux display -pt "$TMUX_PANE:?" '#pane_index'
                      this will show pane number.






                      share|improve this answer














                      In tmux, each new pane gets an unique value, which you can access using environment variable TMUX_PANE.
                      tmux display -pt "$TMUX_PANE:?" '#pane_index'
                      this will show pane number.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jul 5 '17 at 21:52

























                      answered Jul 5 '17 at 21:46









                      Chetna C

                      1469




                      1469











                      • But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
                        – Kyndig
                        Jul 6 '17 at 18:59











                      • Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
                        – Kyndig
                        Jul 6 '17 at 19:12
















                      • But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
                        – Kyndig
                        Jul 6 '17 at 18:59











                      • Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
                        – Kyndig
                        Jul 6 '17 at 19:12















                      But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
                      – Kyndig
                      Jul 6 '17 at 18:59





                      But that tmux display command would have to be run from the new pane in question. Calling it from the original pane which the keybinding was executed in would just give me the index of the pane I'm already in. So how would I execute it from the new pane and communicate the resulting output back to the original pane? If I could do that, that would mean I had already gotten into the new pane. To be more concrete; this is what I currrently have been trying to do in my .tmux.conf:
                      – Kyndig
                      Jul 6 '17 at 18:59













                      Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
                      – Kyndig
                      Jul 6 '17 at 19:12




                      Sorry, I ran out of edit time on the above comment. This is basically what I'm trying to do in my .tmux.conf: "bind s tmux split-window ; send-keys -t $new_pane_id -l "run_this_command" ; send-keys -t $new_pane_id Enter " But I don't know how to get $new_pane_id...
                      – Kyndig
                      Jul 6 '17 at 19:12










                      up vote
                      0
                      down vote













                      I did it by sending the new pane's id back through a named pipe.



                      mkfifo pane_id
                      tmux split-window -h ; send-keys 'echo $TMUX_PANE > pane_id' Enter ; select-pane -t "$TMUX_PANE"
                      cat pane_id





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        I did it by sending the new pane's id back through a named pipe.



                        mkfifo pane_id
                        tmux split-window -h ; send-keys 'echo $TMUX_PANE > pane_id' Enter ; select-pane -t "$TMUX_PANE"
                        cat pane_id





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I did it by sending the new pane's id back through a named pipe.



                          mkfifo pane_id
                          tmux split-window -h ; send-keys 'echo $TMUX_PANE > pane_id' Enter ; select-pane -t "$TMUX_PANE"
                          cat pane_id





                          share|improve this answer












                          I did it by sending the new pane's id back through a named pipe.



                          mkfifo pane_id
                          tmux split-window -h ; send-keys 'echo $TMUX_PANE > pane_id' Enter ; select-pane -t "$TMUX_PANE"
                          cat pane_id






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 17 at 4:48









                          user240515

                          101




                          101



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f375567%2ftmux-after-split-window-how-do-i-know-the-new-pane-id%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?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?