[ACCEPTED]-How to get the active tmux window's name?-tmux

Accepted answer
Score: 29

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

tmux display-message -p '#W'

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

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

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

Score: 2

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


command [flags] This specifies 8 one of a set of commands used to control 7 tmux, as described in the following sections. If 6 no commands are specified, the 5 new-session command is assumed.

You can find 4 full list of tmux commands (two last arguments) in 3 the manual, but now you interest is '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 2 you can see active window marked as '(active)'. This 1 is what you were looking for?

Score: 2

First list all window names and active status, the 2 active one will end with 1, then extract 1 the name before it

 tmux lsw -F '#{window_name}#{window_active}'|sed -n 's|^\(.*\)1$|\1|p'

More Related questions