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. 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.
Sessions
First things first. Let’s figure out what I have.
Listing sessions
- command
list-sessions
- alias
ls
I can list sessions with list-sessions
.
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.
Whatever.
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 numbering. 2
is the name of the session, and that stayed true even when I quit session 1
.
Switching to different sessions
- command
switch-client
- alias
switchc
- shortcut
C-b )
/C-b (
- options
-t N
target-n
next-p
previous
Used to be I’d get at that other session by opening a new tab in my terminal and telling 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 switch-client
.
We can cycle through sessions without targeting them, too. A -n
argument cycles to the next, while -p
cycles to the previous.
NOTE
Okay, key bindings might help here. Cycle through your Tmux sessions with C-b ) and C-b (.
I don’t think so much about tabbed terminals anymore. I do forget which session holds work stuff and which holds site stuff, though.
Renaming sessions
- command
rename-session
- shortcut
- C-b $
- alias
rename
- usage
rename -t N <name>
- options
-t
target
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?
Windows
Listing windows
- command
list-windows
- alias
lsw
- options
-a
all
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.
Renaming windows
- command
rename-window
- alias
renamew
- usage
rename-window -t N <NAME>
- options
-t N
target 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 mplayer
.
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.
Resources
Where did I get all this?
- tmux cheat sheet
- tmux man page — which you can get at on your own system with
man tmux
Backlinks
Got a comment? A question? More of a comment than a question?
Talk to me about this page on: mastodon
Added to vault 2024-01-15. Updated on 2024-02-01