- Fixed bugs which caused errors while running tmux post installation.
- Updated tmux-powerline to reflect tun0 IP when connected using VPN.
- Cleaned up tmux-powerline; removed status-date and sysstat_loadavg.
Tmux's configuration, that supercharges your tmux and builds cozy and cool terminal environment.
- Features
- Installation
- General settings
- Key bindings
- Status line
- Nested tmux sessions
- Copy mode
- Clipboard integration
- Themes and customization
- Prefix is configured as "Ctrl-a"
- support for nested tmux sessions
- local vs remote specific session configuration
- scroll and copy mode improvements
- integration with OSX or Linux clipboard (works for local, remote, and local+remote nested session scenario)
- supercharged status line
- renew tmux and shell environment (SSH_AUTH_SOCK, DISPLAY, SSH_TTY) when reattaching back to old session
- prompt to rename window right after it's created
- newly created windows and panes retain current working directory
- monitor windows for activity/silence
- highlight focused pane
- merge current session with existing one (move all windows)
- configurable visual theme/colors, with some elements borrowed from Powerline
- integration with 3rd party plugins: tmux-sidebar, tmux-copycat, tmux-open,)
Status line widgets:
- CPU, memory usage
- username and hostname
- battery information in status line
- visual indicator when you press
prefix
- visual indicator when you're in
Copy
mode - visual indicator when pane is zoomed
- toggle visibility of status line
Prerequisites:
- tmux >= "v2.4"
- OSX, Linux (tested on Ubuntu 14 and CentOS7), FreeBSD (tested on 11.1)
Personally, I use it on OSX 10.11.5 El Capitan through iTerm2.
On OSX you can install latest 2.6 version with brew install tmux
. On Linux it's better to install from source, because official repositories usually contain outdated version. For example, CentOS7 - v1.8 from base repo, Ubuntu 14 - v1.8 from trusty/main. For how to install from source, see this gist or just google it.
To install tmux-config:
$ git clone https://github.com/iamkashz/tmux-config.git
$ ./tmux-config/install.sh
install.sh
script does following:
- copies files to
~/.tmux
directory - symlink tmux config file at
~/.tmux.conf
, existing~/.tmux.conf
will be backed up - Tmux Plugin Manager will be installed at default location
~/.tmux/plugins/tpm
, unless already present - required tmux plugins will be installed
Finally, you can jump into a new tmux session:
$ tmux new
Windows and pane indexing starts from 1
rather than 0
. Scrollback history limit is set to 20000
. Automatic window renameing is turned off. Aggresive resizing is on. Message line display timeout is 1.5s
. Mouse support in on
.
256 color palette support is turned on, make sure that your parent terminal is configured properly. See here and there
# parent terminal
$ echo $TERM
xterm-256color
# jump into a tmux session
$ tmux new
$ echo $TERM
screen-256color
So ~/.tmux.conf
overrides default key bindings for many action, to make them more reasonable, easy to recall and comfortable to type.
tmux key | Description |
C-a |
Default prefix, used instead of "C-b". Same prefix is used in screen program, and it's easy to type. The only drawback of "C-a" is that underlying shell does not receive the keystroke to move to the beginning of the line. |
<prefix> C-e |
Open ~/.tmux.conf file in your $EDITOR |
<prefix> C-r |
Reload tmux configuration from ~/.tmux.conf file |
<prefix> r |
Rename current window |
<prefix> R |
Rename current session |
<prefix> _ |
Split new pane horizontally |
<prefix> | |
Split new pane vertically |
<prefix> < |
Select next pane |
<prefix> > |
Select previous pane |
<prefix> ← |
Select pane on the left |
<prefix> → |
Select pane on the right |
<prefix> ↑ |
Select pane on the top |
<prefix> ↓ |
Select pane on the bottom |
<prefix> C-← |
Resize pane to the left |
<prefix> C-→ |
Resize pane to the right |
<prefix> C-↑ |
Resize pane to the top |
<prefix> C-↓ |
Resize pane to the bottom |
<prefix> > |
Move to next window |
<prefix> < |
Move to previous window |
<prefix> Tab |
Switch to most recently used window |
<prefix> L |
Link window from another session by entering target session and window reference |
<prefix> \ |
Swap panes back and forth with 1st pane. When in main-horizontal or main-vertical layout, the main panel is always at index 1. This keybinding let you swap secondary pane with main one, and do the opposite. |
<prefix> C-o |
Swap current active pane with next one |
<prefix> + |
Toggle zoom for current pane |
<prefix> x |
Kill current pane |
<prefix> X |
Kill current window |
<prefix> C-x |
Kill other windows but current one (with confirmation) |
<prefix> Q |
Kill current session (with confirmation) |
<prefix> C-u |
Merge current session with another. Essentially, this moves all windows from current session to another one |
<prefix> d |
Detach from session |
<prefix> D |
Detach other clients except current one from session |
<prefix> C-s |
Toggle status bar visibility |
<prefix> m |
Monitor current window for activity |
<prefix> M |
Monitor current window for silence by entering silence period |
<prefix> F12 |
Switch off all key binding and prefix hanling in current window. See "Nested sessions" paragraph for more info |
I've started with Powerline as a status line, but then realized it's too fat for my Macbook 15'' display, it hardly can fit all those fancy arrows, widgets and separators, so that I can only see one window "tab".
So I decide to make my feet wet, with the idea to keep it dense, and include essential widgets. Sometimes it tries to replicate OSX topbar (battery, date time).
The left part contains only current session name. The right part contains CPU & Memory Usage, username@hostname, tun0 IP (if connected to VPN) and battery indicator.
You might want to hide / unhide status bar using <prefix> C-s
keybinding.
One prefers using tmux on local machine to supercharge their terminal emulator experience, other use it only for remote scenarios to retain session/state in case of disconnect. Things are getting more complex, when you want to be on both sides. You end up with nested session, and face the question: How you can control inner session, since all keybindings are caught and handled by outer session?. Community provides several possible solutions.
The most common is to press C-a
prefix twice. First one is caught by local session, whereas second is passed to remote one. Nothing extra steps need to be done, this works out of the box. However, root keytable bindings are still handled by outer session, and cannot be passed to inner one.
Second attempt to tackle this issue, is to setup 2 individual prefixes, C-b
for local session, and C-a
for remote session. And, you know, it feels like:
And finally accepted solution, turn off all keybindings and key prefix handling in outer session, when working with inner one. This way, outer session just sits aside, without interfering keystrokes passed to inner session. Credits to http://stahlke.org/dan/tmux-nested/ and this Github issue
So, how it works. When in outer session, simply press F12
to toggle off all keybindings handling in outer session. Now work with inner session using the same keybinding scheme and same keyprefix. Press F12
to turn on outer session back.
You might notice that when key bindings are "OFF", special [OFF]
visual indicator is shown in the status line, and status line changes its style (colored to gray).
Remote session is detected by existence of $SSH_CLIENT
variable. When session is remote, following changes are applied:
- status line is docked to bottom; so it does not stack with status line of local session
- some widgets are removed from status line: battery, date time. The idea is to economy width, so on wider screens you can open two remote tmux sessions in side-by-side panes of single window of local session.
You can apply remote-specific settings by extending ~/.tmux/.tmux.remote.conf
file.
There are some tweaks to copy mode and scrolling behavior, you should be aware of.
There is a root keybinding to enter Copy mode: M-Up
. Once in copy mode, you have several scroll controls:
- scroll by line:
M-Up
,M-down
- scroll by half screen:
M-PageUp
,M-PageDown
- scroll by whole screen:
PageUp
,PageDown
- scroll by mouse wheel, scroll step is changed from
5
lines to2
Space
starts selection, Enter
copies selection and exits copy mode. List all items in copy buffer using prefix C-p
, and paste most recent item from buffer using prexix p
.
y
just copies selected text and is equivalent to Enter
, Y
copies whole line, and D
copies by the end of line.
Also, note, that when text is copied any trailing new lines are stripped. So, when you paste buffer in a command prompt, it will not be immediately executed.
You can also select text using mouse. Default behavior is to copy text and immediately cancel copy mode on MouseDragEnd
event. This is annoying, because sometimes I select text just to highlight it, but tmux drops me out of copy mode and reset scroll by the end. I've changed this behavior, so MouseDragEnd
does not execute copy-selection-and-cancel
action. Text is copied, but copy mode is not cancelled and selection is not cleared. You can then reset selection by mouse click.
When you copy text inside tmux, it's stored in private tmux buffer, and not shared with system clipboard. Same is true when you SSH onto remote machine, and attach to tmux session there. Copied text will be stored in remote's session buffer, and not shared/transported to your local system clipboard. And sure, if you start local tmux session, then jump into nested remote session, copied text will not land in your system clipboard either.
This is one of the major limitations of tmux, that you might just decide to give up using it. Let's explore possible solutions:
- share text with OSX clipboard using "pbcopy"
- share text with OSX clipboard using reattach-to-user-namespace wrapper to access "pbcopy" from tmux environment (seems on OSX 10.11.5 ElCapitan this is not needed, since I can still access pbcopy without this wrapper).
- share text with X selection using "xclip" (store text in primary and clipboard selections). Works on Linux when DISPLAY variable is set.
All solutions above are suitable for sharing tmux buffer with system clipboard for local machine scenario.
On OSX you might need to install reattach-to-user-namespace
wrapper: brew install reattach-to-user-namespace
, and make sure OSC 52 sequence handling is turned on in iTerm. (Preferences -> General -> Applications in Terminal may access clipboard).
On Linux, make sure xclip
is installed.
All colors related to theme are declared as variables. You can change them in ~/.tmux.conf
.
# This is a theme CONTRACT, you are required to define variables below
# Change values, but not remove/rename variables itself
color_dark="$color_black"
color_light="$color_white"
color_session_text="$color_blue"
color_status_text="colour245"
color_main="$color_orange"
color_secondary="$color_purple"
color_level_ok="$color_green"
color_level_warn="$color_yellow"
color_level_stress="$color_red"
color_window_off_indicator="colour088"
color_window_off_status_bg="colour238"
color_window_off_status_current_bg="colour254"
Note, that variables are not extracted to dedicated file, as it should be, because for some reasons, tmux does not see variable values after sourcing theme.conf
file. Don't know why.