3.4 KiB
Tmux Configuration
I use tmux infrequently as I'm usually running a bunch of Terminals from within Emacs. Laugh all you want, but Emacs is my terminal multiplexer. That said, frequent network connectivity and long-running jobs make a tmux helpful on a remote server.
Remote Installation
Log in an install tmux on a RedHat-based system with a yum command:
sudo yum install -y tmux
And on my Ubuntu systems:
sudo dpkg install tmux
Remote Configuration
Copy the following to $HOME/~/.tmux.conf:
set-option -g prefix C-`
set -g status-right "| docker "
set-option -g allow-rename off
# Start windows and panes at 1, not 0
set -g base-index 1
set -g pane-base-index 1
# Bind function keys.
bind -n F1 select-window -t 1
bind -n F2 select-window -t 2
bind -n F3 select-window -t 3
bind -n F4 select-window -t 4
bind -n F5 select-window -t 5
bind -n F6 select-window -t 6
bind -n F7 select-window -t 7
bind -n F8 select-window -t 8
bind -n F9 select-window -t 9
bind -n F10 select-window -t 10
Not sure why screen and tmux chose such awful prefix keybindings as C-a and C-b, so I change this to C-`.
I'm not a tmux power user, as changing windows is about all I do, so I bind the function keys to change tabs.
The following ~/.bash_aliases enhance tmux:
#!/bin/sh
# The following aliases have been installed on this machine.
# - `nw` to create a new Tmux window. Give ‘er a command.
alias nw='tmux new-window'
# - `root` for a TMUX window as the root user.
alias root='nw -n root "sudo su -" '
When using Docker sessions on the remote system, the go and logs opens a new window:
# - `go` to connect to a docker container
function go {
nw -n "$1" "sudo docker exec -it $1 bash"
}
# - `logs` for displaying the logs from a container
function logs {
nw -n $1-logs "sudo docker logs -f $*"
}
After writing a number of helper aliases, I find it helpful to see those aliases when I roll into a remote server, so put this in the .bashrc file:
if [ "$HOME/.bash_aliases" ]
then
source "$HOME/.bash_aliases"
grep '^# ' "$HOME/.bash_aliases" | sed 's/^# *//'
echo
fi
Note: this can interfere with Tramp.
Local Access
For a collection of long-running and highly verbose programs (like a remote Anisble run), I use iTerm on a MacOS with a special binding to create Mac-widgets in tmux.
ssh -t laptop 'tmux -CC attach || tmux -CC'