How to get the name of the active tmux window?

I want to write a script that gets the name of the active tmux window and uses it as a variable for my vim session. Is it possible? I looked at the tmux manual and saw nothing.

+7
vim tmux
source share
2 answers

You can use display-message -p to request the name of the active window (among other things):

 tmux display-message -p '#W' 

If you want to target a specific window, you can use -t :

 tmux -t «target-window» display-message -p '#W' 

See the man page for various ways to specify the target window (search for the “target window” in the “Commands” section).

+10
source share

SYNOPSIS tmux [-28lquvVC] [-c shell-command] [-f file] [-L socket-name] [-S socket-path] [command [flags]]

PASS

[flags] command This indicates one of the set of commands used to control tmux, as described in the following sections. If no commands are specified, it is assumed that a new session command is used.

You can find a complete list of tmux commands in the manual (the last two arguments), but now you are interested in list-windows.

 tmux list-windows 0: zsh [156x40] [layout aebd,156x40,0,0,0] @0 1: mc [156x40] [layout aebe,156x40,0,0,1] @1 (active) 

As you can see the active window is marked "(active)". Is this what you were looking for?

0
source share

All Articles