Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the active tmux window's name?

Tags:

vim

tmux

I want to write a script that gets the active tmux window's name and uses it as a variable for my vim session. Is this possible? I looked through the tmux manual and didn't see anything.

like image 726
Jon Trainor Avatar asked May 27 '14 21:05

Jon Trainor


People also ask

How do I find my tmux session name?

Just run “tmux” or “tmux new” and a new terminal will open. The tmux session will show by default a green bar at the bottom of the terminal. This green bar shows some information about the tmux session. The first information element shown in this bar, as in the example above, is the session name.

How do I create a tmux session name?

Using the Prefixes to Control Tmux By default, the prefix is CTRL+B. That is, we have to press the keys CTRL+B and then the command. For example, to create a new session, the command would be C. So, to create a new session we need to press CTRL+B and next C – CTRL+B, C.

How do I change the current name in tmux?

There is a default keybinding that you can use <prefix>+$ to rename the current session in the tmux command line. I've also had this keybinding kicking around for years, but I rarely use it anymore. You will see why in an upcoming video.

How do I open tmux pane?

Start tmuxPress Ctrl+B followed by 1 to go to the first new window you created. You can also "walk" through your open windows using Ctrl+B and N (for Next) or P (for Previous).


1 Answers

You can use display-message -p to query 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 the various ways to specify a target window (search for “target-window” in the Commands section).

like image 171
Chris Johnsen Avatar answered Sep 30 '22 14:09

Chris Johnsen