💾 Archived View for thrig.me › tech › tmux.gmi captured on 2024-08-18 at 19:15:48. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-12-28)
-=-=-=-=-=-=-
http://man.openbsd.org/man1/tmux.1
tmux is one of those swiss army chainsaws that can be used in many different ways. Some will run a single huge terminal and therein tmux with many panes. I instead generally run four xterms, each with a tmux instance, and may sometimes attach a terminal with a larger (or much larger) font fullscreen to limit distractions. With four terminals and focus follows mouse it's pretty easy to move to a target that takes up roughly 25 percent of the screen.
Sometimes too easy, though I do have scripts to enable or disable the mouse, usually for games so that brushing the trackpad does not push keyboard activity into some other window. Brogue got mouse support compiled out of it, but that is a different story.
A lot of my tmux.conf is turning off features, since I do not use panes, and do not want accidental keystrokes getting tmux into some weird mode. Others will want those keys. I have customized the keys a lot; notably emacs mode is used nowhere, so control+j and control+k do next-window and previous-window. This makes it quick to flip through the usually few open windows.
set-option -g status-keys vi set-window-option -g mode-keys vi set-option -g prefix C-p unbind-key C-b bind-key C-p last-window bind-key c copy-mode # control+p : is pretty awkward to type bind-key '!' command-prompt bind-key v paste-buffer bind-key -T copy-mode-vi C send-keys -X copy-line bind-key g capture-pane -eJ bind-key G capture-pane -eJ -S - -E - bind-key s run "tmux save-buffer - > ~/tmp/tmux-`date +%s`.out" bind-key -n C-j next-window bind-key -n C-k previous-window bind-key R source-file ~/.tmux.conf \; display-message "source-file done" bind-key m new-window
There are some nifty things you can do in copy and paste mode. This will need some dedicated practice and refreshes over time to stay competent at it. (Maybe turn off the mouse to get into the practice of copying and pasting only with tmux?)
This saves some typing, gets the flags right, and demands a session name to create or attach to.
#!/bin/sh # tmn - start a new (or resume an existing) session exec tmux -u new-session -A -c "$HOME" -s "${1:?need a session name}"
#!/bin/sh # tcmd - show tmux commands exec tmux list-windows '-aF#S:#I #W'
A script that lists what commands are running in what windows might be handy. The four tmux sessions are pa, re, ci, and vo starting from upper left and going clockwise. I tend not to have too many windows open, usually just two or three per tmux instance, though that number may drift up if I'm busy on something. The "," command can be
$ tcmd ci:0 vi ci:1 ksh pa:0 COM pa:1 irssi re:0 ksh re:1 ksh vo:0 less vo:1 midnoi
Chat is in the upper left session (pa) for historical reasons, and midnoi is a lojban dictionary tool. One use for this is to move windows around. Sometimes I will switch to a music-editing mode, in which case there will be mupdf and one tall xterm adjacent. In this case I may want an editor and chat in usually the upper right or "re" session, and to close the pa, ci, and vo sessions. So the chat will need to be moved to the re session.
$ tmux movew -s pa:1 -at re:0 $ tcmd | grep irssi re:1 irssi
And then you can move it back. "-a" here means "after", but the combination flag "-at ..." is maybe a good mnemonic.
$ tmux movew -s re:1 -at pa:0
Probably if I did this more I'd write a wrapper script, maybe "foo source-window dest-window" and then figure out what exactly to call foo so I do not forget it.
Another use for the tmux session:window-number indicators is to find processes by name, lookup their tty, and then associate that tty with the tmux indicator. This is a good way to find vi or w3m sessions that you are not sure where exactly they are in what tmux window.
$ j PID TTY CMD 58599 ci:0 vi tmux.gmi $ j man PID TTY CMD 39472 vo:0 man -T ascii tmux
j (portable) and j.c (not portable)
tags #tmux