💾 Archived View for laniakea.rodoste.de › tui › tmux.gmi captured on 2024-05-12 at 15:19:46. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-11-04)

-=-=-=-=-=-=-

🏠 home

tmux: terminal multiplexer

2023-05-01

Tmux is a terminal multiplexer that is allows to split a terminal window into multiple panes and add multiple virtual windows within a single tmux session.

On top of that tmux allows you to detach from a session and reconnect later. Sessions are preserved until the system reboots. Multiple sessions can be managed and switched between.

Panes live inside a single window. Windows live inside a single session.

The session preservation feature makes tmux extremely useful when connecting to remote computers: Combinations of windows and panes — for example for different users on that computer — can be created and arranged once, then detached and attached to as needed. All over one single SSH connection.

Long-running processes are safe from disconnects since tmux keeps them running even if your SSH connection drops.

The panes feature isn't very useful for me since I'm using a tiling window manager to begin with. Having multiple virtual windows per session saves on screenspace though. But the killer feature for me comes with the plugins ‘continuum’ and ‘resurrect’: If configured just right, they will …well… resurrect all applications that were running in the windows and panes, even across system reboots.

On my desktop I use this to preserve pane tilings and launch apps that I'll inevitably use anyway, like my mail client, gemini space reader, matrix client, ncmpcpp music client… it is _so_ convenient.

On my selfhosted server I use it to have ready-made login shells for common users.

In the command list below, those command marked with a * are customized.

links and resources

tmux Getting Started wiki page

awesome tmux - list of howtos, plugins, themes

TPM, the tmux plugin manager

console commands

| command                            | description                          |
| ---------------------------------- | -------------------------------------|
| tmux                               | start a new unnamed session          |
| tmux new -s docker                 | start a new session named docker     |
| tmux ls                            | lists available sessions             |
| tmux attach -t [name]              | re-attach to existing session [name] |
| tmux rename-session -t [old] [new] | renames a session                    |
| tmux kill-session -t [name]        | kills a session and everything in it |

keyboard shortcuts

| keybind              | description                                        |
| -------------------- | -------------------------------------------------- |
| <prefix> ?           | show keybinds                                      |
| <prefix> :           | open the command prompt                            |

handling panes

| keybind                | description                                      |
| ---------------------- | ------------------------------------------------ |
| <prefix> b           * | create a new pane to the right of current        |
| <prefix> v           * | create a new pane below the current              |
| <prefix> hljk        * | navigate between panes                           |
| <prefix> Ctrl-[CURSOR] | resize pane                                      |
| <prefix> x             | close current pane                               |
| <prefix> z             | zoom / unzoom current pane                       |
| exit                   | exit current pane / window when last pane        |

handling windows

| keybind              | description                                        |
| -------------------- | -------------------------------------------------- |
| <prefix> c           | create a new window                                |
| <prefix> [n]         | switch to window [n] inside current session        |
| <prefix> ,           | rename current window                              |
| <prefix> &           | close current window                               |
| <prefix> w           | list windows                                       |
| <prefix> p           | move to previous window                            |
| <prefix> n           | move to next window                                |
| <prefix> a         * | toggle to last active window                       |
| <prefix> .           | move a window (use numeric indexes or cursor keys) |

handling sessions from within a session

| keybind              | description                                        |
| -------------------- | -------------------------------------------------- |
| <prefix> s           | switch to a different session from a list          |
| <prefix> d           | detach from current session                        |
| <prefix> $           | rename session                                     |
| <prefix> (           | move to previous session                           |
| <prefix> )           | move to next session                               |

plugins

Tmux has strong plugin support. It all starts with the tmux plugin manager:

TPM, the tmux plugin manager

To add new plugins, add them to your tmux.conf file and press Ctrl-b I to load new plugins.

tweaks and config changes

Tmux reads config options from ~/.tmux.conf or my personal preference ~/.config/tmux/tmux.conf but _only_ when the server is started, not when a new session is created or attached to. My config file looks like this:

#---- remap prefix key to Ctrl-a --------------------------
unbind C-b
set-option -g prefix C-a 
bind-key C-a send-prefix

#---- enable mouse control --------------------------------
set -g mouse on 

#---- start window numbering from 1, not 0 ----------------
set -g base-index 1

#---- set 256 color space ---------------------------------
set-option -g default-terminal "xterm-256color"
set-option -ga terminal-overrides ',xterm-256color:Tc'

#---- keybinds --------------------------------------------
# pane creation same as SwayWM
bind-key    -T prefix   v     split-window
bind-key    -T prefix   b     split-window -h
# pane navigation same as vim
bind-key    -T prefix   h     select-pane -L
bind-key    -T prefix   l     select-pane -R
bind-key    -T prefix   j     select-pane -D
bind-key    -T prefix   k     select-pane -U
# left-/right-shift windows in a session by one
bind-key    -r         "<"    swap-window -d -t -1
bind-key    -r         ">"    swap-window -d -t +1

#---- resurrection ----------------------------------------
set -g @continuum-restore on
set -g @resurrect-capture-pane-contents "on"
# declare additional applications as safe for resurrection
set -g @resurrect-processes "amfora ncmpcpp w3m"

#---- theme and styling -----------------------------------
# using nova theme customization to make it look like tokyo night
#    since the tokyo night theme isn't working for me
set -g @plugin "o0th/tmux-nova"

set -g @nova-nerdfonts true
set -g @nova-nerdfonts-left 
set -g @nova-nerdfonts-right 

set -g @nova-pane-active-border-style "#7da6ff"
set -g @nova-pane-border-style "#444b6a"
set -g @nova-status-style-bg "#32344a"
set -g @nova-status-style-fg "#787c99"
set -g @nova-status-style-active-bg "#449dab"
set -g @nova-status-style-active-fg "#32344a"
set -g @nova-status-style-double-bg "#acb0d0"

set -g @nova-pane "#I#{?pane_in_mode,  #{pane_mode},}  #W"

set -g @nova-segment-mode "#S #{?client_prefix,Ω,ω}"
set -g @nova-segment-mode-colors "#ad8ee6 #32344a"

set -g @nova-segment-whoami "#(whoami)@#h"
set -g @nova-segment-whoami-colors "#ad8ee6 #32344a"

set -g @nova-rows 0
set -g @nova-segments-0-left "mode"
set -g @nova-segments-0-right "whoami"

# list of plugins
set -g @plugin "tmux-plugins/tpm"
set -g @plugin "tmux-plugins/tmux-sensible"
set -g @plugin "tmux-plugins/tmux-resurrect"
set -g @plugin "tmux-plugins/tmux-continuum"

#---- initialize TMUX plugin manager ----------------------
#     (keep this line at the very bottom of tmux.conf)
run "~/.config/tmux/plugins/tpm/tpm"

---

see all articles on command-line tools