Naming things in tmux
I got the basics of tmux down:
- starting a new session
- creating new windows
- moving between windows
- scrolling back in a window buffer
And that’s about it.
After this long you might expect me to know more. Alas, no.
At some point I realized you can have more than one tmux session going at a time. Now my normal day includes the site in one session, work in another, and sometimes a third for random puttering.
I need to manage everything better.
Using Tmux commands
Although tmux binds keys to commands, it’s easier for me to remember words than keys. It’s part of why I still use taskwarrior more than Org mode. Because of that, I’ll focus on the tmux commands.
You can send them directly to
tmux in an open shell.
You don’t have a shell handy? [[C-b :]] will pull up a quick Tmux command prompt to enter your commands:
If your command produces output, it will display in place of your current window until you hit [[ENTER]].
On to the commands themselves. I’ve added some highlights along the way, with command full names, aliases, and useful arguments — but not all arguments.
First things first. Let’s figure out what I have.
I can list sessions with
This shows two sessions. The first one — currently attached, which means its the one I’m typing in right now — contains three windows, and has been open a few days. The other is open with some work stuff. Yes, I know. On a Saturday. I’m working on that “life/work balance” thing.
By writing a blog post.
Anyways, that number on the start of each entry identifies the session. It
starts at zero, and keeps going up with each new session until you quit all
your tmux sessions and start again. Quitting a session won’t affect the
2 is the name of the session, and that stayed true even when I
Switching to different sessions
- [[C-b )]] / [[C-b (]]
Used to be I’d get at that other session by opening a new tab in my terminal
tmux to attach to it, making sure to detach it from whatever
other connections I may have had open.
Then I learned that we can switch to my other sessions with
We can cycle through sessions without targeting them, too. A
cycles to the next, while
-p cycles to the previous.
I don’t think so much about tabbed terminals anymore. I do forget which session holds work stuff and which holds site stuff, though.
- [[C-b $]]
rename -t N <name>
I’m not stuck with the tmux-assigned session numbers for identification. I can rename them!
Does that help?
It sure does. Oh and it sorts the listing alphabetically. Good to know.
With several sessions going at once — it happens sometimes — names tell me what I intended to do with my time. Makes switching to a targeted session easier for me as well.
I gave each of my sessions a purpose. Now. What’s going on with the windows inside the sessions?
list-windows summarizes the windows in my current session.
Let’s see. There’s a window with two panes, one of which is a Zsh session. There’s a second Zsh session. And — uh — a third Zsh session.
I can even list every window in every session!
That’s not very helpful. The named sessions help clarify things somewhat, but the windows are just a lot of Zsh.
Let’s fix that.
rename-window -t N <NAME>
-t Ntarget window
I can rename the windows within my session.
There we go. I’m writing this post in Neovim, serving my site with
Hugo locally for review, and listening to the KEXP stream via
Heck, I can rename windows in my other session if I like.
Does that help?
It does! My sessions and windows all make sense! More or less.
Some folks might prefer naming their windows according to the current process. Maybe even automating that process. For my own brain, a named purpose is generally more informative and more persistent than any executable.
So much more I could learn, but this covers enough to call it a post.
Besides, I need to get back to work.
Where did I get all this?
- tmux cheat sheet
- tmux man page — which you can get at on your own system with