TMUX: After split-window, how do I know the new pane id?
Another way, especially useful for shell scripts.
tmux split-window -P -F "#{pane_id}"
will output the pane id, (e.g. %4) into stdout
so you can do
bash_var=$(tmux split-window -P -F "#{pane_id}"
if you want to capture it in a shell/bash variable.
Taken from here: https://github.com/tmux-plugins/tmux-sidebar/blob/master/scripts/toggle.sh