├── .gitattributes ├── CHANGELOG.md ├── LICENSE.md ├── README.md └── sensible.tmux /.gitattributes: -------------------------------------------------------------------------------- 1 | # Force text files to have unix eols, so Windows/Cygwin does not break them 2 | *.* eol=lf 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### master 4 | - remove `detach-on-destroy` 5 | - do not set `aggressive-resize` on iTerm terminal 6 | - disable `detach-on-destroy` 7 | 8 | ### v3.0.0, 2015-06-24 9 | - remove 'almost sensible' feature 10 | 11 | ### v2.3.0, 2015-06-24 12 | - update to support \*THE\* latest tmux version 13 | - bugfix for `prefix + R` key binding 14 | - fix for tmux 2.0 `default-terminal` option (thanks @kwbr) 15 | 16 | ### v2.2.0, 2015-02-10 17 | - bugfix in `key_binding_not_set`: the regex is now properly detecting key 18 | bindings with `-r` flag. 19 | - enable `aggressive-resize` 20 | 21 | ### v2.1.0, 2014-12-12 22 | - check before binding `prefix + prefix` (@m1foley) 23 | - enable `focus-events` 24 | - deprecate 'almost sensible' feature. The reason for this is to focus the 25 | plugin on doing just one thing. 26 | 27 | ### v2.0.0, 2014-10-03 28 | - bugfix: prevent exiting tmux if 'reattach-to-user-namespace' is not installed 29 | - remove all mouse-related options 30 | - introduce 'almost sensible' setting and options 31 | 32 | ### v1.1.0, 2014-08-30 33 | - bugfix: determine the default shell from the $SHELL env var on OS X 34 | - set `mode-mouse on` by default 35 | - do not make any decision about the prefix, just enhance it 36 | - update `README.md`. List options set in the plugin. 37 | - do *not* set `mode-mouse on` by default because some users don't like it 38 | - if a user changes default prefix but binds `C-b` to something else, do not 39 | unbind `C-b` 40 | 41 | ### v1.0.0, 2014-07-30 42 | - initial work on the plugin 43 | - add readme 44 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Bruno Sutic 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included 11 | in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 19 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tmux sensible 2 | 3 | A set of tmux options that should be acceptable to everyone. 4 | 5 | Inspired by [vim-sensible](https://github.com/tpope/vim-sensible). 6 | 7 | Tested and working on Linux, OSX and Cygwin. 8 | 9 | ### Principles 10 | 11 | - `tmux-sensible` options should be acceptable to **every** tmux user!
12 | If any of the options bothers you, please open an issue and it will probably 13 | be updated (or removed). 14 | - if you think a new option should be added, feel free to open a pull request. 15 | - **no overriding** of user defined settings.
16 | Your existing `.tmux.conf` settings are respected and they won't be changed. 17 | That way you can use `tmux-sensible` if you have a few specific options. 18 | 19 | ### Goals 20 | 21 | - group standard tmux community options in one place 22 | - remove clutter from your `.tmux.conf` 23 | - educate new tmux users about basic options 24 | 25 | ### Options 26 | 27 | ```tmux 28 | # Address vim mode switching delay (http://superuser.com/a/252717/65504) 29 | set -s escape-time 0 30 | 31 | # Increase scrollback buffer size from 2000 to 50000 lines 32 | set -g history-limit 50000 33 | 34 | # Increase tmux messages display duration from 750ms to 4s 35 | set -g display-time 4000 36 | 37 | # Refresh 'status-left' and 'status-right' more often, from every 15s to 5s 38 | set -g status-interval 5 39 | 40 | # (OS X) Fix pbcopy/pbpaste for old tmux versions (pre 2.6) 41 | set -g default-command "reattach-to-user-namespace -l $SHELL" 42 | 43 | # Upgrade $TERM 44 | set -g default-terminal "screen-256color" 45 | 46 | # Emacs key bindings in tmux command prompt (prefix + :) are better than 47 | # vi keys, even for vim users 48 | set -g status-keys emacs 49 | 50 | # Focus events enabled for terminals that support them 51 | set -g focus-events on 52 | 53 | # Super useful when using "grouped sessions" and multi-monitor setup 54 | setw -g aggressive-resize on 55 | ``` 56 | 57 | ### Key bindings 58 | 59 | ```tmux 60 | # Easier and faster switching between next/prev window 61 | bind C-p previous-window 62 | bind C-n next-window 63 | ``` 64 | 65 | Above bindings enhance the default `prefix + p` and `prefix + n` bindings by 66 | allowing you to hold `Ctrl` and repeat `a + p`/`a + n` (if your prefix is 67 | `C-a`), which is a lot quicker. 68 | 69 | ```tmux 70 | # Source .tmux.conf as suggested in `man tmux` 71 | bind R source-file '~/.tmux.conf' 72 | ``` 73 | 74 | "Adaptable" key bindings that build upon your `prefix` value: 75 | 76 | ```tmux 77 | # If prefix is 'C-a' 78 | bind C-a send-prefix 79 | bind a last-window 80 | ``` 81 | 82 | If prefix is `C-b`, above keys will be `C-b` and `b`.
83 | If prefix is `C-z`, above keys will be `C-z` and `z`... you get the idea. 84 | 85 | ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) 86 | 87 | Add plugin to the list of TPM plugins in `.tmux.conf`: 88 | 89 | ```tmux 90 | set -g @plugin 'tmux-plugins/tmux-sensible' 91 | ``` 92 | 93 | Hit `prefix + I` to fetch the plugin and source it. That's it! 94 | 95 | ### Manual Installation 96 | 97 | Clone the repo: 98 | 99 | $ git clone https://github.com/tmux-plugins/tmux-sensible ~/clone/path 100 | 101 | Add this line to the bottom of `.tmux.conf`: 102 | 103 | ```tmux 104 | run-shell ~/clone/path/sensible.tmux 105 | ``` 106 | 107 | Reload TMUX environment with `$ tmux source-file ~/.tmux.conf`, and that's it. 108 | 109 | ### Other goodies 110 | 111 | You might also find these useful: 112 | 113 | - [copycat](https://github.com/tmux-plugins/tmux-copycat) 114 | improve tmux search and reduce mouse usage 115 | - [pain control](https://github.com/tmux-plugins/tmux-pain-control) 116 | useful standard bindings for controlling panes 117 | - [resurrect](https://github.com/tmux-plugins/tmux-resurrect) 118 | persists tmux environment across system restarts 119 | 120 | ### License 121 | 122 | [MIT](LICENSE.md) 123 | -------------------------------------------------------------------------------- /sensible.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | # used to match output from `tmux list-keys` 6 | KEY_BINDING_REGEX="bind-key[[:space:]]\+\(-r[[:space:]]\+\)\?\(-T prefix[[:space:]]\+\)\?" 7 | 8 | is_osx() { 9 | local platform=$(uname) 10 | [ "$platform" == "Darwin" ] 11 | } 12 | 13 | iterm_terminal() { 14 | [[ "${TERM_PROGRAM}" =~ ^iTerm || "${LC_TERMINAL}" =~ ^iTerm ]] 15 | } 16 | 17 | command_exists() { 18 | local command="$1" 19 | type "$command" >/dev/null 2>&1 20 | } 21 | 22 | # returns prefix key, e.g. 'C-a' 23 | prefix() { 24 | tmux show-option -gv prefix 25 | } 26 | 27 | # if prefix is 'C-a', this function returns 'a' 28 | prefix_without_ctrl() { 29 | local prefix="$(prefix)" 30 | echo "$prefix" | cut -d '-' -f2 31 | } 32 | 33 | option_value_not_changed() { 34 | local option="$1" 35 | local default_value="$2" 36 | local option_value=$(tmux show-option -gv "$option") 37 | [ "$option_value" == "$default_value" ] 38 | } 39 | 40 | server_option_value_not_changed() { 41 | local option="$1" 42 | local default_value="$2" 43 | local option_value=$(tmux show-option -sv "$option") 44 | [ "$option_value" == "$default_value" ] 45 | } 46 | 47 | key_binding_not_set() { 48 | local key="${1//\\/\\\\}" 49 | if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then 50 | return 1 51 | else 52 | return 0 53 | fi 54 | } 55 | 56 | key_binding_not_changed() { 57 | local key="$1" 58 | local default_value="$2" 59 | if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then 60 | # key still has the default binding 61 | return 0 62 | else 63 | return 1 64 | fi 65 | } 66 | 67 | get_tmux_config() { 68 | local tmux_config_xdg="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf" 69 | local tmux_config="$HOME/.tmux.conf" 70 | 71 | if [ -f "${tmux_config_xdg}" ]; then 72 | echo "${tmux_config_xdg}" 73 | else 74 | echo ${tmux_config} 75 | fi 76 | } 77 | 78 | main() { 79 | # OPTIONS 80 | 81 | # address vim mode switching delay (http://superuser.com/a/252717/65504) 82 | if server_option_value_not_changed "escape-time" "500"; then 83 | tmux set-option -s escape-time 0 84 | fi 85 | 86 | # increase scrollback buffer size 87 | if option_value_not_changed "history-limit" "2000"; then 88 | tmux set-option -g history-limit 50000 89 | fi 90 | 91 | # tmux messages are displayed for 4 seconds 92 | if option_value_not_changed "display-time" "750"; then 93 | tmux set-option -g display-time 4000 94 | fi 95 | 96 | # refresh 'status-left' and 'status-right' more often 97 | if option_value_not_changed "status-interval" "15"; then 98 | tmux set-option -g status-interval 5 99 | fi 100 | 101 | # required (only) on OS X 102 | if is_osx && command_exists "reattach-to-user-namespace" && option_value_not_changed "default-command" ""; then 103 | tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL" 104 | fi 105 | 106 | # upgrade $TERM, tmux 1.9 107 | if option_value_not_changed "default-terminal" "screen"; then 108 | tmux set-option -g default-terminal "screen-256color" 109 | fi 110 | # upgrade $TERM, tmux 2.0+ 111 | if server_option_value_not_changed "default-terminal" "screen"; then 112 | tmux set-option -s default-terminal "screen-256color" 113 | fi 114 | 115 | # emacs key bindings in tmux command prompt (prefix + :) are better than 116 | # vi keys, even for vim users 117 | tmux set-option -g status-keys emacs 118 | 119 | # focus events enabled for terminals that support them 120 | tmux set-option -g focus-events on 121 | 122 | # super useful when using "grouped sessions" and multi-monitor setup 123 | if ! iterm_terminal; then 124 | tmux set-window-option -g aggressive-resize on 125 | fi 126 | 127 | # DEFAULT KEY BINDINGS 128 | 129 | local prefix="$(prefix)" 130 | local prefix_without_ctrl="$(prefix_without_ctrl)" 131 | 132 | # if C-b is not prefix 133 | if [ $prefix != "C-b" ]; then 134 | # unbind obsolete default binding 135 | if key_binding_not_changed "C-b" "send-prefix"; then 136 | tmux unbind-key C-b 137 | fi 138 | 139 | # pressing `prefix + prefix` sends to the shell 140 | if key_binding_not_set "$prefix"; then 141 | tmux bind-key "$prefix" send-prefix 142 | fi 143 | fi 144 | 145 | # If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows. 146 | # Works for any prefix character. 147 | if key_binding_not_set "$prefix_without_ctrl"; then 148 | tmux bind-key "$prefix_without_ctrl" last-window 149 | fi 150 | 151 | # easier switching between next/prev window 152 | if key_binding_not_set "C-p"; then 153 | tmux bind-key C-p previous-window 154 | fi 155 | if key_binding_not_set "C-n"; then 156 | tmux bind-key C-n next-window 157 | fi 158 | 159 | # source `.tmux.conf` file - as suggested in `man tmux` 160 | if key_binding_not_set "R"; then 161 | local tmux_config=$(get_tmux_config) 162 | 163 | tmux bind-key R run-shell " \ 164 | tmux source-file ${tmux_config} > /dev/null; \ 165 | tmux display-message 'Sourced ${tmux_config}!'" 166 | fi 167 | } 168 | main 169 | --------------------------------------------------------------------------------