mirror of
https://github.com/tmux-plugins/tmux-sensible.git
synced 2025-09-09 15:41:23 +00:00
Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
2ce7679f9d | |||
e1aabe4b8a | |||
fff9a53723 | |||
2476f3fb23 | |||
3ea5b9f6b9 | |||
9d61936c53 | |||
e725d88256 | |||
ba0b52d999 | |||
b5a1c2ade5 | |||
22d1305cb7 | |||
c20bc5c4e2 | |||
294e607f83 | |||
d2565e5f10 | |||
babfd71d08 | |||
c95eb0d88d | |||
df5b537d21 | |||
bbff707eaa | |||
13f58a8870 | |||
c908b42f2b | |||
9beab4784c | |||
4a584b0799 | |||
615906df94 | |||
4967aa0ce7 | |||
fa3e8b91ea | |||
74c4a76bfa | |||
89a51c86e3 | |||
47df9983a9 | |||
6a9c4a78ff | |||
97904bc483 |
33
CHANGELOG.md
33
CHANGELOG.md
@ -2,6 +2,39 @@
|
|||||||
|
|
||||||
### master
|
### master
|
||||||
|
|
||||||
|
### v3.0.0, 2015-06-24
|
||||||
|
- remove 'almost sensible' feature
|
||||||
|
|
||||||
|
### v2.3.0, 2015-06-24
|
||||||
|
- update to support \*THE\* latest tmux version
|
||||||
|
- bugfix for `prefix + R` key binding
|
||||||
|
- fix for tmux 2.0 `default-terminal` option (thanks @kwbr)
|
||||||
|
|
||||||
|
### v2.2.0, 2015-02-10
|
||||||
|
- bugfix in `key_binding_not_set`: the regex is now properly detecting key
|
||||||
|
bindings with `-r` flag.
|
||||||
|
- enable `aggressive-resize`
|
||||||
|
|
||||||
|
### v2.1.0, 2014-12-12
|
||||||
|
- check before binding `prefix + prefix` (@m1foley)
|
||||||
|
- enable `focus-events`
|
||||||
|
- deprecate 'almost sensible' feature. The reason for this is to focus the
|
||||||
|
plugin on doing just one thing.
|
||||||
|
|
||||||
|
### v2.0.0, 2014-10-03
|
||||||
|
- bugfix: prevent exiting tmux if 'reattach-to-user-namespace' is not installed
|
||||||
|
- remove all mouse-related options
|
||||||
|
- introduce 'almost sensible' setting and options
|
||||||
|
|
||||||
|
### v1.1.0, 2014-08-30
|
||||||
|
- bugfix: determine the default shell from the $SHELL env var on OS X
|
||||||
|
- set `mode-mouse on` by default
|
||||||
|
- do not make any decision about the prefix, just enhance it
|
||||||
|
- update `README.md`. List options set in the plugin.
|
||||||
|
- do *not* set `mode-mouse on` by default because some users don't like it
|
||||||
|
- if a user changes default prefix but binds `C-b` to something else, do not
|
||||||
|
unbind `C-b`
|
||||||
|
|
||||||
### v1.0.0, 2014-07-30
|
### v1.0.0, 2014-07-30
|
||||||
- initial work on the plugin
|
- initial work on the plugin
|
||||||
- add readme
|
- add readme
|
||||||
|
83
README.md
83
README.md
@ -1,23 +1,18 @@
|
|||||||
# Tmux sensible
|
# Tmux sensible
|
||||||
|
|
||||||
A set of tmux options that should be acceptable for everyone.
|
A set of tmux options that should be acceptable to everyone.
|
||||||
|
|
||||||
Inspired by [vim-sensible](https://github.com/tpope/vim-sensible).
|
Inspired by [vim-sensible](https://github.com/tpope/vim-sensible).
|
||||||
|
|
||||||
### Principles
|
### Principles
|
||||||
|
|
||||||
- `tmux-sensible` options should be acceptable to **every** tmux user!<br/>
|
- `tmux-sensible` options should be acceptable to **every** tmux user!<br/>
|
||||||
If any option bothers you, please open an issue and it will probably be
|
If any of the options bothers you, please open an issue and it will probably
|
||||||
updated (or removed).
|
be updated (or removed).
|
||||||
- if you think a new option should be added, feel free to open a pull request.
|
- if you think a new option should be added, feel free to open a pull request.
|
||||||
- **no overriding** of user defined settings.<br/>
|
- **no overriding** of user defined settings.<br/>
|
||||||
Your existing `.tmux.conf` settings are respected and they won't be changed.
|
Your existing `.tmux.conf` settings are respected and they won't be changed.
|
||||||
That way you can use `tmux-sensible` if you have a few specific options.
|
That way you can use `tmux-sensible` if you have a few specific options.
|
||||||
See [feature section](#example-feature) for an example.
|
|
||||||
- [source code](https://github.com/tmux-plugins/tmux-sensible/blob/master/sensible.tmux)
|
|
||||||
is the authoritative documentation.<br/>
|
|
||||||
It's really not that scary and you should have a look, even if you're a
|
|
||||||
tmux beginner.
|
|
||||||
|
|
||||||
### Goals
|
### Goals
|
||||||
|
|
||||||
@ -25,25 +20,70 @@ Inspired by [vim-sensible](https://github.com/tpope/vim-sensible).
|
|||||||
- remove clutter from your `.tmux.conf`
|
- remove clutter from your `.tmux.conf`
|
||||||
- educate new tmux users about basic options
|
- educate new tmux users about basic options
|
||||||
|
|
||||||
### Example feature
|
### Options
|
||||||
|
|
||||||
Sets tmux prefix to `Ctrl-a`.
|
# utf8 is on
|
||||||
|
set -g utf8 on
|
||||||
|
set -g status-utf8 on
|
||||||
|
|
||||||
# set prefix to `Ctrl-a`
|
# address vim mode switching delay (http://superuser.com/a/252717/65504)
|
||||||
tmux set-option -g prefix C-a
|
set -s escape-time 0
|
||||||
tmux unbind-key C-b
|
|
||||||
|
|
||||||
Since user defined `.tmux.conf` settings are respected, if prefix is set to
|
# increase scrollback buffer size
|
||||||
`Ctrl-z` - it won't be overriden!
|
set -g history-limit 50000
|
||||||
|
|
||||||
|
# tmux messages are displayed for 4 seconds
|
||||||
|
set -g display-time 4000
|
||||||
|
|
||||||
|
# refresh 'status-left' and 'status-right' more often
|
||||||
|
set -g status-interval 5
|
||||||
|
|
||||||
|
# set only on OS X where it's required
|
||||||
|
set -g default-command "reattach-to-user-namespace -l $SHELL"
|
||||||
|
|
||||||
|
# upgrade $TERM
|
||||||
|
set -g default-terminal "screen-256color"
|
||||||
|
|
||||||
|
# emacs key bindings in tmux command prompt (prefix + :) are better than
|
||||||
|
# vi keys, even for vim users
|
||||||
|
set -g status-keys emacs
|
||||||
|
|
||||||
|
# focus events enabled for terminals that support them
|
||||||
|
set -g focus-events on
|
||||||
|
|
||||||
|
# super useful when using "grouped sessions" and multi-monitor setup
|
||||||
|
setw -g aggressive-resize on
|
||||||
|
|
||||||
|
### Key bindings
|
||||||
|
|
||||||
|
# easier and faster switching between next/prev window
|
||||||
|
bind C-p previous-window
|
||||||
|
bind C-n next-window
|
||||||
|
|
||||||
|
Above bindings enhance the default `prefix + p` and `prefix + n` bindings by
|
||||||
|
allowing you to hold `Ctrl` and repeat `a + p`/`a + n` (if your prefix is
|
||||||
|
`C-a`), which is a lot quicker.
|
||||||
|
|
||||||
|
# source .tmux.conf as suggested in `man tmux`
|
||||||
|
bind R source-file '~/.tmux.conf'
|
||||||
|
|
||||||
|
"Adaptable" key bindings that build upon your `prefix` value:
|
||||||
|
|
||||||
|
# if prefix is 'C-a'
|
||||||
|
bind C-a send-prefix
|
||||||
|
bind a last-window
|
||||||
|
|
||||||
|
If prefix is `C-b`, above keys will be `C-b` and `b`.<br/>
|
||||||
|
If prefix is `C-z`, above keys will be `C-z` and `z`... you get the idea.
|
||||||
|
|
||||||
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
|
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
|
||||||
|
|
||||||
Add plugin to the list of TPM plugins in `.tmux.conf`:
|
Add plugin to the list of TPM plugins in `.tmux.conf`:
|
||||||
|
|
||||||
set -g @tpm_plugins " \
|
set -g @tpm_plugins ' \
|
||||||
tmux-plugins/tpm \
|
tmux-plugins/tpm \
|
||||||
tmux-plugins/tmux-sensible \
|
tmux-plugins/tmux-sensible \
|
||||||
"
|
'
|
||||||
|
|
||||||
Hit `prefix + I` to fetch the plugin and source it. That's it!
|
Hit `prefix + I` to fetch the plugin and source it. That's it!
|
||||||
|
|
||||||
@ -59,12 +99,7 @@ Add this line to the bottom of `.tmux.conf`:
|
|||||||
|
|
||||||
run-shell ~/clone/path/sensible.tmux
|
run-shell ~/clone/path/sensible.tmux
|
||||||
|
|
||||||
Reload TMUX environment:
|
Reload TMUX environment with `$ tmux source-file ~/.tmux.conf`, and that's it.
|
||||||
|
|
||||||
# type this in terminal
|
|
||||||
$ tmux source-file ~/.tmux.conf
|
|
||||||
|
|
||||||
You might also want to restart your tmux server, just in case.
|
|
||||||
|
|
||||||
### Other goodies
|
### Other goodies
|
||||||
|
|
||||||
@ -74,6 +109,8 @@ You might also find these useful:
|
|||||||
improve tmux search and reduce mouse usage
|
improve tmux search and reduce mouse usage
|
||||||
- [pain control](https://github.com/tmux-plugins/tmux-pain-control)
|
- [pain control](https://github.com/tmux-plugins/tmux-pain-control)
|
||||||
useful standard bindings for controlling panes
|
useful standard bindings for controlling panes
|
||||||
|
- [resurrect](https://github.com/tmux-plugins/tmux-resurrect)
|
||||||
|
persists tmux environment across system restarts
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
|
@ -2,34 +2,64 @@
|
|||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
# used to match output from `tmux list-keys`
|
||||||
|
KEY_BINDING_REGEX="bind-key[[:space:]]\+\(-r[[:space:]]\+\)\?\(-T prefix[[:space:]]\+\)\?"
|
||||||
|
|
||||||
is_osx() {
|
is_osx() {
|
||||||
local platform=$(uname)
|
local platform=$(uname)
|
||||||
[ "$platform" == "Darwin" ]
|
[ "$platform" == "Darwin" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command_exists() {
|
||||||
|
local command="$1"
|
||||||
|
type "$command" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# returns prefix key, e.g. 'C-a'
|
||||||
|
prefix() {
|
||||||
|
tmux show-option -gv prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
# if prefix is 'C-a', this function returns 'a'
|
||||||
|
prefix_without_ctrl() {
|
||||||
|
local prefix="$(prefix)"
|
||||||
|
echo "$prefix" | cut -d '-' -f2
|
||||||
|
}
|
||||||
|
|
||||||
option_value_not_changed() {
|
option_value_not_changed() {
|
||||||
local option="$1"
|
local option="$1"
|
||||||
local default_value="$2"
|
local default_value="$2"
|
||||||
local option_value=$(tmux show-option -gv "$option")
|
local option_value=$(tmux show-option -gv "$option")
|
||||||
[ $option_value == $default_value ]
|
[ "$option_value" == "$default_value" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
server_option_value_not_changed() {
|
server_option_value_not_changed() {
|
||||||
local option="$1"
|
local option="$1"
|
||||||
local default_value="$2"
|
local default_value="$2"
|
||||||
local option_value=$(tmux show-option -sv "$option")
|
local option_value=$(tmux show-option -sv "$option")
|
||||||
[ $option_value == $default_value ]
|
[ "$option_value" == "$default_value" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
key_binding_not_set() {
|
key_binding_not_set() {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
if $(tmux list-keys | grep -q "bind-key[[:space:]]\+${key}"); then
|
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key_binding_not_changed() {
|
||||||
|
local key="$1"
|
||||||
|
local default_value="$2"
|
||||||
|
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
|
||||||
|
# key still has the default binding
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
@ -39,12 +69,6 @@ main() {
|
|||||||
# enable utf8 in tmux status-left and status-right
|
# enable utf8 in tmux status-left and status-right
|
||||||
tmux set-option -g status-utf8 on
|
tmux set-option -g status-utf8 on
|
||||||
|
|
||||||
# set Ctrl-a as Tmux prefix
|
|
||||||
if option_value_not_changed "prefix" "C-b"; then
|
|
||||||
tmux set-option -g prefix C-a
|
|
||||||
tmux unbind-key C-b
|
|
||||||
fi
|
|
||||||
|
|
||||||
# address vim mode switching delay (http://superuser.com/a/252717/65504)
|
# address vim mode switching delay (http://superuser.com/a/252717/65504)
|
||||||
if server_option_value_not_changed "escape-time" "500"; then
|
if server_option_value_not_changed "escape-time" "500"; then
|
||||||
tmux set-option -s escape-time 0
|
tmux set-option -s escape-time 0
|
||||||
@ -66,34 +90,51 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# required (only) on OS X
|
# required (only) on OS X
|
||||||
if is_osx && option_value_not_changed "default-command" ""; then
|
if is_osx && command_exists "reattach-to-user-namespace" && option_value_not_changed "default-command" ""; then
|
||||||
tmux set-option -g default-command "reattach-to-user-namespace -l bash"
|
tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# upgrade $TERM
|
# upgrade $TERM, tmux 1.9
|
||||||
if option_value_not_changed "default-terminal" "screen"; then
|
if option_value_not_changed "default-terminal" "screen"; then
|
||||||
tmux set-option -g default-terminal "screen-256color"
|
tmux set-option -g default-terminal "screen-256color"
|
||||||
fi
|
fi
|
||||||
|
# upgrade $TERM, tmux 2.0+
|
||||||
# enable mouse features for terminals that support it
|
if server_option_value_not_changed "default-terminal" "screen"; then
|
||||||
tmux set-option -g mouse-resize-pane on
|
tmux set-option -s default-terminal "screen-256color"
|
||||||
tmux set-option -g mouse-select-pane on
|
fi
|
||||||
tmux set-option -g mouse-select-window on
|
|
||||||
|
|
||||||
# emacs key bindings in tmux command prompt (prefix + :) are better than
|
# emacs key bindings in tmux command prompt (prefix + :) are better than
|
||||||
# vi keys, even for vim users
|
# vi keys, even for vim users
|
||||||
tmux set-option -g status-keys emacs
|
tmux set-option -g status-keys emacs
|
||||||
|
|
||||||
|
# focus events enabled for terminals that support them
|
||||||
|
tmux set-option -g focus-events on
|
||||||
|
|
||||||
|
# super useful when using "grouped sessions" and multi-monitor setup
|
||||||
|
tmux set-window-option -g aggressive-resize on
|
||||||
|
|
||||||
# DEFAULT KEY BINDINGS
|
# DEFAULT KEY BINDINGS
|
||||||
|
|
||||||
# Ctrl-a + a send `Ctrl-a` to the shell
|
local prefix="$(prefix)"
|
||||||
if key_binding_not_set "a"; then
|
local prefix_without_ctrl="$(prefix_without_ctrl)"
|
||||||
tmux bind-key a send-prefix
|
|
||||||
|
# if C-b is not prefix
|
||||||
|
if [ $prefix != "C-b" ]; then
|
||||||
|
# unbind obsolte default binding
|
||||||
|
if key_binding_not_changed "C-b" "send-prefix"; then
|
||||||
|
tmux unbind-key C-b
|
||||||
|
fi
|
||||||
|
|
||||||
|
# pressing `prefix + prefix` sends <prefix> to the shell
|
||||||
|
if key_binding_not_set "$prefix"; then
|
||||||
|
tmux bind-key "$prefix" send-prefix
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ctrl-a + Ctrl-a switch between alternate windows
|
# If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows.
|
||||||
if key_binding_not_set "C-a"; then
|
# Works for any prefix character.
|
||||||
tmux bind-key C-a last-window
|
if key_binding_not_set "$prefix_without_ctrl"; then
|
||||||
|
tmux bind-key "$prefix_without_ctrl" last-window
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# easier switching between next/prev window
|
# easier switching between next/prev window
|
||||||
@ -106,7 +147,7 @@ main() {
|
|||||||
|
|
||||||
# source `.tmux.conf` file - as suggested in `man tmux`
|
# source `.tmux.conf` file - as suggested in `man tmux`
|
||||||
if key_binding_not_set "R"; then
|
if key_binding_not_set "R"; then
|
||||||
tmux bind-key R run-shell -b ' \
|
tmux bind-key R run-shell ' \
|
||||||
tmux source-file ~/.tmux.conf > /dev/null; \
|
tmux source-file ~/.tmux.conf > /dev/null; \
|
||||||
tmux display-message "Sourced .tmux.conf!"'
|
tmux display-message "Sourced .tmux.conf!"'
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user