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.
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.
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.
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.
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).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With