TMUX: After split-window, how do I know the new pane id?
Clash 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.
tmux
add a comment |Â
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.
tmux
add a comment |Â
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.
tmux
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
tmux
asked Jul 5 '17 at 20:14
Kyndig
285
285
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
add a comment |Â
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.
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
add a comment |Â
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited 12 mins ago
answered Jul 7 '17 at 22:21
Kyndig
285
285
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Apr 17 at 4:48
user240515
101
101
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password