If you are running commands inside a tmux pane, then you can use the TMUX_PANE environment variable* to target the “containing” pane.
To identify the “containing” window:
tmux display-message -pt "$TMUX_PANE" '#:#'
Or, depending on your needs, you might like to use window_id
. The man page has a list of other format variables. For example, when run inside a pane, this command
tmux display-message -pt "$TMUX_PANE" '#'
will output 1
if the pane’s window is active or 0
otherwise.
You might use pane_active
if you care whether the specific pane is active.
If you want to check on some other pane, you will need to supply your own target-pane identifier (like sess:win.0
).
* tmux 1.5 and later sets TMUX_PANE
for the pane to a unique value when starting its initial command; other programs run via this initial program will generally inherit this environment variable.