Skip to content

Commit

Permalink
Merge pull request #92 from arcticicestudio/feature/gh-66-tmux
Browse files Browse the repository at this point in the history
tmux
  • Loading branch information
arcticicestudio authored Nov 30, 2017
2 parents 82d8cfd + 831535f commit 56595bd
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 0 deletions.
118 changes: 118 additions & 0 deletions snowblocks/tmux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
* [Configuration](#configuration)
* [24-bit "True Color" Support](#24-bit-true-color-support)
* [Automatic tpm Installation](#automatic-tpm-installation)
* [Key Mappings](#key-mappings)
* [Development](#development)
* [Manual Plugin Loading](#manual-plugin-loading)

# Configuration

## 24-bit "True color" Support

[tmux][tmux] supports 24-bit *True color* since version [2.2][tc-version].

To check if tmux has been compiled with *True color* support start `tmux` and run

```sh
tmux info | grep Tc
```

If the output is `Tc: (flag) true` tmux supports *True color*, otherwise the output will be `Tc: [missing]`.

The 24-bit colors can be tested by run this inside tmux:

```awk
awk 'BEGIN{
s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
for (colnum = 0; colnum<77; colnum++) {
r = 255-(colnum*255/76);
g = (colnum*510/76);
b = (colnum*255/76);
if (g>255) g = 510-g;
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
printf "%s\033[0m", substr(s,colnum+1,1);
}
printf "\n";
}'
```

If the line looks "stepwise" tmux does not use 24-bit *True color*:

![](https://raw.githubusercontent.com/arcticicestudio/igloo/develop/snowblocks/tmux/assets/scrot-doc-tc-support-disabled.png)

Otherwise the line should have smooth transitions:

![](https://raw.githubusercontent.com/arcticicestudio/igloo/develop/snowblocks/tmux/assets/scrot-doc-tc-support-enabled.png)

The `$TERM` environment variable is important for tmux as described in the official [tmux FAQ][tmux-faq]. The variable must be initialized with a terminal that supports 256 colors (`*-256color`). More information about 24-bit color terminal support can be found in the [ArchWiki][archw-24bit].

If the terminal supports *True color* the `terminal-overrides` option must be set in the `~/.tmux.conf` file for the `$TERM` value and the *True color* `Tc` tmux flag:

```sh
set-option -ga terminal-overrides ",xterm-256color:Tc"
```

This will reflect the actual `$TERM` outside of tmux and enables full compatibility.

For other terminals, replace `xterm-256color` with the relevant terminal type, stored in `$TERM`, **including the important `Tc` terminfo extension flag!**.

See the *tmux(1)* man page for details about the `Tc` [terminfo][terminfo] extension.

## Automatic tpm Installation

If [tpm][tpm-gh] doesn't exist it can be automatically installed by adding this check from the [official tpm wiki][tpm-autoinstall] to `~/.tmux.conf`:

```sh
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"
```
After cloning the tpm repository the [plugin installer helper script][tpm-bin-plugin-installer] will be run to install all configured plugins.
# Key Mappings
## Split windows
* Horizontal: <kbd>Prefix</kbd> - <kbd>h</kbd>
* Vertical: <kbd>Prefix</kbd> - <kbd>v</kbd>
## Switch windows
* Switch to previous window: <kbd>Prefix</kbd> - <kbd>Shift</kbd> + <kbd>🠨</kbd>
* Switch to next window: <kbd>Prefix</kbd> - <kbd>Shift</kbd> + <kbd>🠪</kbd>
## Resize panes
* Resize left: <kbd>Prefix</kbd> - <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>🠨</kbd>
* Resize right: <kbd>Prefix</kbd> - <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>🠪</kbd>
* Resize up: <kbd>Prefix</kbd> - <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>🠩</kbd>
* Resize down: <kbd>Prefix</kbd> - <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>🠫</kbd>
Please read the documentation of the [Tilix][gh-sb-tilix] snowblock about the [compatibility with the tmux key mappings][gh-sb-tilix-keymap-tmux-comp].
## Synchronize typing between panes
* Toggle typing synchronization: <kbd>Prefix</kbd> - <kbd>e</kbd>
# Development
## Manual Plugin Loading
Local plugins can be manually loaded without using [tpm][tpm-gh] by adding this to the `~/.tmux.conf`:
```sh
run-shell ~/.tmux/plugins/nord-tmux/nord.tmux
```
[archw-24bit]: https://wiki.archlinux.org/index.php/Tmux#24-bit_color
[faq]: https://github.com/tmux/tmux/wiki/FAQ#what-is-term-and-what-does-it-do
[gh-sb-tilix]: https://github.com/arcticicestudio/igloo/tree/develop/snowblocks/tilix
[gh-sb-tilix-keymap-tmux-comp]: https://github.com/arcticicestudio/igloo/tree/develop/snowblocks/tilix#tmux-snowblock-compatibility
[ghg-truecolor]: https://gist.github.com/XVilka/8346728
[tc-version]: https://github.com/tmux/tmux/commit/427b8204268af5548d09b830e101c59daa095df9
[terminfo]: https://en.wikipedia.org/wiki/Terminfo
[tmux]: https://tmux.github.io
[tpm-gh]: https://github.com/tmux-plugins/tpm
[tpm-autoinstall]: https://github.com/tmux-plugins/tpm/blob/master/docs/automatic_tpm_installation.md
[tpm-bin-plugin-installer]: https://github.com/tmux-plugins/tpm/blob/master/bin/install_plugins
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions snowblocks/tmux/snowblock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"clean": ["~"]
},
{
"link": {
"~/.tmux.conf": null
}
}
]
123 changes: 123 additions & 0 deletions snowblocks/tmux/tmux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright (c) 2016-2017 Arctic Ice Studio <[email protected]>
# Copyright (c) 2016-2017 Sven Greb <[email protected]>

# Project: igloo
# Repository: https://github.com/arcticicestudio/igloo
# License: MIT
# References:
# https://github.com/arcticicestudio/igloo/blob/develop/snowblocks/tmux/README.md

#+-----------+
#+ Bootstrap +
#+-----------+

# If "tpm" is not already installed, automatically clone the repository and install all configured plugins.
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"

#+---------+
#+ Plugins +
#+---------+

#+--- UI ---+
set -g @plugin "tmux-plugins/tmux-prefix-highlight"

#+--- Color Themes ---+
set -g @plugin "arcticicestudio/nord-tmux"

#+-----------------------+
#+ Plugin Configurations +
#+-----------------------+

#+--- tmux-plugins/tmux-prefix-highlight ---+
set -g @prefix_highlight_show_copy_mode "on"

#+---------+
#+ Options +
#+---------+

# Enable 256 color support
set -g default-terminal "xterm-256color"

# Enable 24-bit "True color" support
set-option -ga terminal-overrides ",xterm-256color:Tc"

# Use vi(m) key bindings in copy mode and in the status line
setw -g mode-keys vi
set -g status-keys vi

# Renumber windows on close
set -g renumber-windows on

# Increase the maximum history length
set -g history-limit 10000

# Enable mouse mode
set -g mouse on

# Automatically set window titles
set-window-option -g automatic-rename on
set-option -g set-titles on

# Use multiple commands without sending the prefix-key within 1 second (default is 500 ms).
set -g repeat-time 1000

# No delay for escape key press
set -sg escape-time 0

#+--------------+
#+ Key Bindings +
#+--------------+

# <Prefix>-<h|v> for window splitting
unbind %
bind h split-window -v
unbind '"'
bind v split-window -h

# <Prefix>-<e> to toggle synchronization
bind e setw synchronize-panes

# <Prefix>-<Ctrl>-<Shift><Arrow> to resize panes
bind -r C-S-Down resize-pane -D
bind -r C-S-Up resize-pane -U
bind -r C-S-Left resize-pane -L
bind -r C-S-Right resize-pane -R

# <Prefix>-<Ctrl>-<Arrow> to switch panes
bind -r C-Left select-pane -L
bind -r C-Right select-pane -R
bind -r C-Up select-pane -U
bind -r C-Down select-pane -D

# <Prefix>-<Shift>-<Arrow> to switch windows
bind -r S-Left previous-window
bind -r S-Right next-window

# Inherit current working directory for new windows/pane
bind c new-window -c "#{pane_current_path}"

# <Prefix>-<Escape> to enter copy-mode with vi(m) key bindings.
# In copy-mode use <v> to start visual selection and <Enter> to copy the selection.
bind Escape copy-mode
bind -T copy-mode-vi 'v' send-keys -X begin-selection
bind -T copy-mode-vi 'y' send-keys -X copy-selection
bind -T copy-mode-vi 'Space' send-keys -X halfpage-down
bind -T copy-mode-vi 'Bspace' send-keys -X halfpage-up
# Use <Prefix>-<p> to paste the copied content.
unbind p
bind p paste-buffer

# <Prefix>-r to reload the configuration file
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded configuration!"

#+------------+
#+ Preloading +
#+------------+

# Import the local configuration file if it exists
if "test -f ~/.tmux.conf.local" "source '~/.tmux.conf.user'"

# Initialize and run tpm
run "~/.tmux/plugins/tpm/tpm"

0 comments on commit 56595bd

Please sign in to comment.