Yesterday I discovered tmux - what an awesome command line tool!
So powerful, yet so easy to use (and configure!).
If you haven't heard of tmux before, but have used GNU screen then tmux is basically an enhanced screen replacement.
It allows you to set up a set of windows (with panes and tabs), detach from the session, and later reattach. You can also attach multiple users to a tmux session (which is great for pair programming - or if you are giving someone a tour of a server).
Interested You should buy this book - it's short and great:
https://pragprog.com/book/bhtmux/tmux
Basic commands:
New Session
tmux new -s [-d]
Attach to Session
tmux attach -t
Kill Session
tmux kill-session -t
List Sessions
tmux ls
All key commands start with a prefix (by default it is configured to be ctrl+b), most people change this to ctrl+a by the looks of things.
Windows
New Window (c)
Select Window (0-9)
Rename Window (,)
Detach (d)
Panes
Vertical Split (") - a good replacement for this is (|)
Horizontal Split (%) - a good replacement for this is (-)
Swap Panes ({})
Select Pane UDLR
Close Pane (x)
Cycle Pane (o)
Turn Page Into a New Window (!)
- Here is my current tmux config (place in ~/.tmux.conf):
# Setting the prefix from C-b to C-a
set -g prefix C-a
# Free the original Ctrl-b prefix keybinding
unbind C-b
#setting the delay between prefix and command
set -s escape-time 1
# Ensure that we can send Ctrl-A to other apps
bind C-a send-prefix
# Set the base index for windows to 1 instead of 0
set -g base-index 1
# Set the base index for panes to 1 instead of 0
setw -g pane-base-index 1
# Reload the file with Prefix r
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# splitting panes
bind | split-window -h
bind - split-window -v
# moving between panes
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Quick pane selection
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# mouse support - set to on if you want to use the mouse (tmux > 2.1)
#set -g mouse on
#bind m set -g mouse on \; display "Mouse ON"
#bind M set -g mouse off \; display "Mouse OFF"
# mouse support - set to on if you want to use the mouse (tmux < 2.1)
#set -g mode-mouse on
#set -g mouse-resize-pane on
#set -g mouse-select-pane on
#set -g mouse-select-window on
#bind m set -g mode-mouse on \; set -g mouse-resize-pane on \; set -g mouse-select-pane on \; set -g mouse-select-window on \; display "Mouse ON"
#bind M set -g mode-mouse off \; set -g mouse-resize-pane off \; set -g mouse-select-pane off \; set -g mouse-select-window off \; display "Mouse OFF"
# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
# set the status line's colors
set -g status-fg white
set -g status-bg black
setw -g window-status-style fg=cyan
setw -ga window-status-style bg=default
setw -ga window-status-style dim
setw -g window-status-current-style fg=white
setw -ga window-status-current-style bg=black
setw -ga window-status-current-style bright
set -g pane-border-style fg=green
set -ga pane-border-style bg=black
set -g pane-active-border-style fg=white
set -ga pane-active-border-style bg=yellow
set -g message-style fg=white
set -ga message-style bg=black
set -ga message-style bright
set-window-option -g window-status-current-style bg=black
set-window-option -ga window-status-current-style fg=yellow
set-window-option -ga window-status-current-style dim
# Status line left side
set -g status-left-length 40
set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
# Status line right side
# 15% | 28 Nov 18:15
set -g status-right "#(~/battery Discharging) | #[fg=cyan]%d %b %R"
# Update the status bar every sixty seconds
set -g status-interval 60
# Center the window list
set -g status-justify centre
# enable vi keys.
setw -g mode-keys vi
# shortcut for synchronize-panes toggle
bind C-s set-window-option synchronize-panes
# Log output to a text file on demand
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log" 