Convert Figma logo to code with AI

samoshkin logotmux-config

Tmux configuration, that supercharges your tmux to build cozy and cool terminal environment

2,157
498
2,157
45

Top Related Projects

21,777

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️

11,935

Tmux Plugin Manager

:green_book: Example tmux configuration - screen + vim key-bindings, system stat, cpu load bar.

A list of awesome resources for tmux

basic tmux settings everyone can agree on

A pack of various Tmux themes.

Quick Overview

The samoshkin/tmux-config repository provides a comprehensive and opinionated configuration for the popular terminal multiplexer, Tmux. It aims to enhance the user experience and productivity of Tmux by introducing a set of customizations, key bindings, and plugins.

Pros

  • Extensive Customization: The configuration offers a wide range of customizations, including custom key bindings, status bar, and visual enhancements, allowing users to tailor Tmux to their preferences.
  • Improved Productivity: The configuration includes various plugins and settings that streamline common Tmux workflows, such as session management, pane/window navigation, and copy-paste functionality.
  • Well-documented: The repository provides detailed documentation, including instructions for installation, configuration, and usage, making it easy for users to get started with the setup.
  • Active Maintenance: The project is actively maintained, with regular updates and bug fixes, ensuring the configuration remains up-to-date and compatible with the latest Tmux versions.

Cons

  • Opinionated: The configuration is highly opinionated, which may not align with the preferences of all Tmux users. Some users may prefer a more minimalist or custom-tailored approach.
  • Complexity: The extensive customizations and the inclusion of multiple plugins can make the configuration complex, especially for users new to Tmux or those who prefer a more lightweight setup.
  • Potential Compatibility Issues: As the configuration relies on various plugins and external dependencies, there is a possibility of compatibility issues with certain Tmux versions or system configurations.
  • Limited Flexibility: While the configuration offers a wide range of customizations, some users may find it challenging to further modify or extend the setup to their specific needs.

Getting Started

To get started with the samoshkin/tmux-config setup, follow these steps:

  1. Clone the repository:
git clone https://github.com/samoshkin/tmux-config.git
  1. Change to the cloned directory:
cd tmux-config
  1. Install the required dependencies:
./install.sh
  1. Start Tmux and enjoy the enhanced experience:
tmux

The installation script will handle the necessary setup, including installing Tmux (if not already present), creating symlinks for the configuration files, and installing the required plugins.

Competitor Comparisons

21,777

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️

Pros of .tmux

  • More popular and actively maintained (20k+ stars, frequent updates)
  • Extensive documentation and user-friendly setup process
  • Cross-platform compatibility (Linux, macOS, Windows/WSL)

Cons of .tmux

  • Less customizable out-of-the-box compared to tmux-config
  • May require additional configuration for advanced users
  • Fewer pre-configured plugins and integrations

Code Comparison

tmux-config:

set -g status-left "#{?client_prefix,#[fg=$color_orange],#[fg=$color_green]}#H #[fg=$color_aqua]W:#I #[fg=$color_purple]P:#P"
set -g status-right "#{?client_prefix,#[fg=$color_orange],#[fg=$color_green]}$wg_is_keys_off $wg_is_zoomed #{sysstat_cpu} | #{sysstat_mem} | #{sysstat_loadavg} | $wg_user_host | #{online_status}"

.tmux:

set -g status-left '#{?client_prefix,#[fg=colour254]#[bg=colour31]#[bold],#[fg=colour16]#[bg=colour254]#[bold]} #S #{?client_prefix,#[fg=colour31]#[bg=colour234]#[nobold],#[fg=colour254]#[bg=colour234]#[nobold]}'
set -g status-right '#{prefix_highlight} #{?battery_status, #{battery_status},}#{?battery_bar, #{battery_bar},}#{?battery_percentage, #{battery_percentage},} , %R , %d %b | #{username}#{root} | #{hostname} '

Both configurations offer customized status bars, but tmux-config includes system statistics, while .tmux focuses on battery information and user details.

11,935

Tmux Plugin Manager

Pros of tpm

  • Modular plugin management system for tmux
  • Easier to add, remove, and update plugins
  • Large ecosystem of community-contributed plugins

Cons of tpm

  • Requires additional setup and configuration
  • May introduce complexity for users who prefer a simpler setup
  • Potential for conflicts between plugins

Code Comparison

tmux-config:

# Key bindings
bind-key -n C-a send-prefix
bind-key C-a last-window
bind-key a send-prefix

tpm:

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Initialize TMUX plugin manager
run '~/.tmux/plugins/tpm/tpm'

Summary

tmux-config provides a comprehensive, pre-configured tmux setup, while tpm offers a flexible plugin management system. tmux-config is ideal for users who want a ready-to-use configuration, whereas tpm caters to those who prefer customization and modularity. The choice between the two depends on individual preferences and requirements for tmux usage.

:green_book: Example tmux configuration - screen + vim key-bindings, system stat, cpu load bar.

Pros of tmux-config (tony)

  • Simpler configuration with fewer customizations, making it easier for beginners to understand and modify
  • Includes a plugin manager (tpm) for easy installation and management of additional plugins
  • Provides a clean and minimalistic status bar design

Cons of tmux-config (tony)

  • Less comprehensive key bindings and custom functions compared to the samoshkin version
  • Lacks some advanced features like nested tmux session handling and custom copy-mode

Code Comparison

tmux-config (tony):

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

tmux-config (samoshkin):

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# nested tmux session
bind -T root F12  \
    set prefix None \
    set key-table off \
    set status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \
    set window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W# #[fg=$color_window_off_status_current_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \
    set window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \
    if -F '#{pane_in_mode}' 'send-keys -X cancel' \
    refresh-client -S \

The samoshkin version offers more advanced configurations and customizations, while the tony version provides a simpler setup with plugin management capabilities.

A list of awesome resources for tmux

Pros of awesome-tmux

  • Comprehensive collection of tmux resources, plugins, and configurations
  • Regularly updated with community contributions
  • Provides a wide range of options for users to explore and customize their tmux setup

Cons of awesome-tmux

  • Lacks a pre-configured tmux setup, requiring more effort to implement
  • May overwhelm users with too many options, making it difficult to choose
  • No unified theme or consistent design across recommended configurations

Code comparison

tmux-config:

set -g status-left "#{?client_prefix,#[fg=$color_blue],#[fg=$color_status_text]}#[bg=$color_status_bg]$separator_powerline_right#[default]"
set -g status-right "#{?client_prefix,#[fg=$color_blue],#[fg=$color_status_text]}#[bg=$color_status_bg]$separator_powerline_left#[default]"

awesome-tmux:

# No direct code comparison available, as awesome-tmux is a curated list of resources rather than a configuration file

Summary

tmux-config offers a pre-configured tmux setup with a consistent theme and design, while awesome-tmux provides a comprehensive list of resources for users to explore and customize their own tmux environment. tmux-config is better suited for users who want a ready-to-use configuration, while awesome-tmux is ideal for those who prefer to build their own setup from various sources.

basic tmux settings everyone can agree on

Pros of tmux-sensible

  • Lightweight and focused on essential tmux settings
  • Part of the larger tmux-plugins ecosystem, allowing for easy integration with other plugins
  • Regularly maintained and updated

Cons of tmux-sensible

  • Less comprehensive than tmux-config, offering fewer customizations
  • Lacks some advanced features and keybindings present in tmux-config
  • May require additional plugins or configurations for a fully customized setup

Code Comparison

tmux-sensible:

set -g history-limit 50000
set -g display-time 4000
set -g status-interval 5
set -g default-terminal "screen-256color"
set -g focus-events on

tmux-config:

set -g history-limit 5000
set -g display-time 1000
set -g status-interval 10
set -g default-terminal "screen-256color"
set -g mouse on

The code comparison shows that both repositories set similar options, but with different values. tmux-sensible generally opts for higher limits and more frequent updates, while tmux-config includes mouse support by default.

tmux-sensible focuses on providing sensible defaults that work well for most users, while tmux-config offers a more opinionated and feature-rich configuration. Users looking for a simple, plug-and-play solution might prefer tmux-sensible, while those seeking a more comprehensive setup with advanced features may find tmux-config more suitable.

A pack of various Tmux themes.

Pros of tmux-themepack

  • Offers a wide variety of pre-configured themes
  • Easy to install and switch between different themes
  • Lightweight and focused solely on theming

Cons of tmux-themepack

  • Limited functionality compared to tmux-config's comprehensive setup
  • Lacks advanced customization options and keybindings
  • Does not include additional tmux plugins or integrations

Code Comparison

tmux-themepack:

set -g @themepack 'powerline/default/cyan'

tmux-config:

set -g status-left "#{?client_prefix,#[fg=$color_orange],#[fg=$color_green]}#H"
set -g status-right "#{?client_prefix,#[fg=$color_orange],#[fg=$color_aqua]}$wg_is_keys_off $wg_user_host"

The tmux-themepack code shows a simple theme selection, while tmux-config demonstrates more complex status bar customization.

tmux-themepack focuses on providing ready-to-use themes with minimal configuration, making it ideal for users who want a quick and easy way to improve their tmux appearance. However, it lacks the extensive functionality and customization options offered by tmux-config.

tmux-config, on the other hand, provides a more comprehensive tmux setup with advanced features, keybindings, and integrations. It offers greater flexibility for users who want to fine-tune their tmux environment but requires more time and effort to set up and customize.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tmux Configuration

Tmux configuration, that supercharges your tmux and builds cozy and cool terminal environment.

intro

Table of contents

  1. Features
  2. Installation
  3. General settings
  4. Key bindings
  5. Status line
  6. Nested tmux sessions
  7. Copy mode
  8. Clipboard integration
  9. Themes and customization
  10. iTerm2 and tmux integration

Features

  • "C-a" prefix instead of "C-b" (screen like)
  • 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, tmux-plugin-sysstat

Status line widgets:

  • CPU, memory usage, system load average metrics
  • username and hostname, current date time
  • 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
  • online/offline visual indicator
  • toggle visibility of status line

Installation

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/samoshkin/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 presemt
  • required tmux plugins will be installed

Finally, you can jump into a new tmux session:

$ tmux new

General settings

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 propertly. See here and there

# parent terminal
$ echo $TERM
xterm-256color

# jump into a tmux session
$ tmux new
$ echo $TERM
screen-256color

Key bindings

So ~/.tmux.conf overrides default key bindings for many action, to make them more reasonable, easy to recall and comforable to type.

Let's go through them.

If you are an iTerm2 user, third column describes the keybinding of similar "action" in iTerm2. It's possible to reuse very same keys you already get used to and tell iTerm2 to execute analogous tmux actions. See iTerm2 and tmux integration section below.

tmux key Description iTerm2 key
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 ⌘⇧D
<prefix> | Split new pane vertically ⌘D
<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 ^Tab
<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 ⌘⇧Enter
<prefix> x Kill current pane ⌘W
<prefix> X Kill current window ⌘⌥W
<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 -

Status line

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).

Left part: status line left

Right part: status line right

The left part contains only current session name.

Window tabs use Powerline arrows glyphs, so you need to install Powerline enabled font to make this work. See Powerline docs for instructions and here is the collection of patched fonts for powerline users

The right part of status line consists of following components:

  • CPU, memory usage, system load average metrics. Powered by tmux-plugin-sysstat (dislaimed, that's my own development, because I haven't managed to find any good plugin with CPU and memory/swap metrics)
  • username and hostname (invaluable when you SSH onto remote host)
  • current date time
  • battery information
  • visual indicator when you press prefix key: [^A].
  • visual indicator when pane is zoomed: [Z]
  • online/offline visual indicator (just pings google.com)

You might want to hide status bar using <prefix> C-s keybinding.

Nested tmux sessions

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:

tmux in tmux

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.

nested sessions

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).

Local and remote sessions

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.

Copy mode

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 to 2

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.

copy and scroll

Clipboard integration

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" or "xsel" (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. They still does not address remote session scenarios. What we need is some way to transport buffer from remote machine to the clipboard on the local machine, bypassing remote system clipboard.

There are 2 workarounds to address remote scenarios.

Use ANSI OSC 52 escape sequence to talk to controlling/parent terminal and pass buffer on local machine. Terminal should properly undestand and handle OSC 52. Currently, only iTerm2 and XTerm support it. OSX Terminal, Gnome Terminal, Terminator do not.

Second workaround is really involved and consists of local network listener and SSH remote tunneling:

  • SSH onto target machine with remote tunneling on
    ssh -R 2222:localhost:3333  alexeys@192.168.33.100
    
  • When text is copied inside tmux (by mouse, by keyboard by whatever configured shortcut), pipe text to network socket on remote machine
    echo "buffer" | nc localhost 2222
    
  • Buffer will be sent thru SSH remote tunnel from port 2222 on remote machine to port 3333 on local machine.
  • Setup a service on local machine (systemd service unit with socket activation), which listens on network socket on port 3333, and pipes any input to pbcopy command (or xsel, xclip).

This tmux-config does its best to integrate with system clipboard, trying all solutions above in order, and falling back to OSC 52 ANSI escape sequences in case of failure.

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 or xsel is installed. For remote scenarios, you would still need to setup network listener and use SSH remote tunneling, unless you terminal emulators supports OSC 52 sequences.

Themes and customization

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.

iTerm2 and tmux integration

If you're an iTerm use same to me, most likely you already have a muscle memory for most common actions and keybindings (split pane, focus pane, fullscreen pane, move between tabs, create new tab, etc). When I switched to tmux, I found new key table more difficult: more keys to type, don't forget to enter prefix and recall if you've already pressed it or not (compare C-a, c with "⌘T", or C-a -> with "⌘⌥->"). iTerm2 keybinding was so natural to me, so I decided to remap most common keybindings to tell iTerm2 to execute corresponding tmux actions.

You can setup new profile in iTerm preferences to override default keybindings, to tell iTerm to send pre-configured sequences of keys, that will trigger corresponding action in tmux.

iterm preferences

For example, when "^⌘↑" pressed, sequence of bytes 0x01 0x1b 0x5b 0x31 0x3b 0x35 0x41 are sent through terminal to running tmux instance, that interprets them as C-a C-↑ keybinding and triggers resize-pane -U according to our .tmux.conf configuration.

You can get binary representation of any keys, using showkey or od commands

$od -t x1

^A^[[1;5A   // press C-a C-↑ on your keyboard
0000000 01 1b 5b 31 3b 35 41
0000007
$ showkey -a
Press any keys - Ctrl-D will terminate this program

^A        1 0001 0x01
^[[1;5A  27 0033 0x1b
         91 0133 0x5b
         49 0061 0x31
         59 0073 0x3b
         53 0065 0x35
         65 0101 0x41

You can remap whatever key in this way, but I do this only for those ones, which have similar analogous action in tmux and are most common(resize pane, zoom pane, create new window, etc). See table with keybindings above.

As additional step, you can setup this new iTerm profile as default one, and tell it to jump into tmux session right off the start.

iterm tmux default profile

You can then go full screen in iTerm, so iTerm tabs and frame do not distract you (anyway now you're using iTerm just as a tunnel to your tmux, everything else happens inside tmux).

full screen mode