36 Commits

Author SHA1 Message Date
25cb91f42d Merge pull request #66 from jjant/patch-1
Show initial values of modified options
2022-08-14 22:08:18 +02:00
e463ee9a75 Show initial values of modified options 2022-08-14 16:34:49 +01:00
5d089e418e Style change 2021-08-19 09:43:20 +02:00
8e8043c439 Merge pull request #62 from setsevireon/patch-1
XDG-friendly config reload
2021-08-19 09:41:30 +02:00
eba4cbe76f XDG-friendly config reload
`prefix + R` is currently bound to sourcing `~/.tmux.conf`.
For anyone using `~/.config/tmux/tmux.conf` or `${XDG_CONFIG_HOME}/tmux/tmux.conf`,
this binding will be of no use, perhaps even misleading.

This patch tests if the file `${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf` exists,
if affirmative, it sources it, if not, it sources `~/.tmux.conf`.
2021-08-18 20:51:53 -03:00
989d09249e Merge pull request #37 from futuro/regex-fix
Fixed key_binding_not_set regex issue
2021-05-20 12:14:56 +02:00
44af8d8eff Merge pull request #59 from jrjsmrtn/fix-iterm2-aggressive-resize
Fix iTerm2 terminal detection
2021-03-20 11:48:04 +01:00
57d999b7df Fix iTerm2 terminal detection
Fixes: #24
2021-03-19 15:10:57 +01:00
0dd7aed9a0 Remove old UTF8 options
As the code comments say, these options were removed in tmux 2.2.
2021-03-11 12:44:44 +01:00
e91b178ff8 Merge pull request #39 from timss/typo-obsolte
Fix 'obsolte' typo
2017-09-05 17:17:20 +02:00
bb9a833510 Fix 'obsolte' typo 2017-09-03 16:11:52 +02:00
df09a123ef More suscinct and flexible escape char fix
To handle the possibility of the escape character being anywhere in the
key passed to `key_binding_not_set`, I've opted to use parameter
replacement to escape every escape character. This is more suscinct, and
will make sure every '\' is handled.
2016-10-01 19:28:28 -05:00
6bd0e2b221 Fixed key_binding_not_set regex issue
If you run key_binding_not_set against '\' that character will be placed
as is in the regex that's run, and will escape something it shouldn't.
So we test for this and escape the character if necessary.
2016-10-01 19:15:26 -05:00
526110eb9b Quiet warnings for utf8 options
Tmux 2.2 removed `utf8` and `status-utf8` options. Since we still want
to keep these options for earlier tmux versions we're redirecting the
output to /dev/null when setting these commands. This way tmux 2.2 (and
above) users won't get any errors when running this plugin.
2016-04-11 15:41:31 +02:00
b0a8527eb4 Add better cygwin support 2015-10-08 14:28:56 +02:00
3baff4e795 Remove detach-on-destroy 2015-08-10 20:29:25 +02:00
4055083386 Update plugin installation instructions 2015-08-10 20:27:55 +02:00
cd7faa8bba Disable 2015-06-29 18:47:07 +02:00
9a4309ed63 Do not set aggressive-resize on iterm terminal
Related #24
2015-06-29 18:03:58 +02:00
2fe5834f30 Update readme 2015-06-24 16:21:33 +02:00
2ce7679f9d v3.0.0 2015-06-24 16:20:17 +02:00
e1aabe4b8a Remove 'almost sensible' feature 2015-06-24 16:17:49 +02:00
fff9a53723 v2.3.0 2015-06-24 16:12:36 +02:00
2476f3fb23 Fix option for tmux 2.0+ 2015-06-24 15:02:14 +02:00
3ea5b9f6b9 Support *the* latest tmux version 2015-05-08 22:33:06 +02:00
9d61936c53 Bugfix for 'prefix + R' key binding 2015-02-12 16:42:33 +01:00
e725d88256 v2.2.0 2015-02-10 02:13:56 +01:00
ba0b52d999 Enable 2015-02-10 02:13:14 +01:00
b5a1c2ade5 Fix regex in key_binding_not_set
Fixes #15
2014-12-23 23:04:28 +01:00
22d1305cb7 Add a link to tmux-resurrect to the readme 2014-12-12 23:42:14 +01:00
c20bc5c4e2 v2.1.0 2014-12-12 23:25:39 +01:00
294e607f83 Deprecate "almost sensible" feature 2014-12-12 23:17:34 +01:00
d2565e5f10 Enable focus-events 2014-12-12 22:40:09 +01:00
babfd71d08 Update changelog and readme 2014-12-03 13:22:19 +01:00
c95eb0d88d Merge pull request #13 from m1foley/safe_bind_prefix
Don't overwrite $prefix if already bound
2014-12-03 13:19:50 +01:00
df5b537d21 Don't overwrite $prefix if already bound 2014-12-02 17:55:10 -08:00
4 changed files with 115 additions and 92 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Force text files to have unix eols, so Windows/Cygwin does not break them
*.* eol=lf

View File

@ -1,6 +1,28 @@
# Changelog # Changelog
### master ### master
- remove `detach-on-destroy`
- do not set `aggressive-resize` on iTerm terminal
- disable `detach-on-destroy`
### 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 ### v2.0.0, 2014-10-03
- bugfix: prevent exiting tmux if 'reattach-to-user-namespace' is not installed - bugfix: prevent exiting tmux if 'reattach-to-user-namespace' is not installed

118
README.md
View File

@ -1,106 +1,97 @@
# 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).
### Core principles Tested and working on Linux, OSX and Cygwin.
- core `tmux-sensible` options should be acceptable to **every** tmux user!<br/> ### Principles
If any option bothers you, please open an issue and it will probably be
updated (or removed). - `tmux-sensible` options should be acceptable to **every** tmux user!<br/>
If any of the options bothers you, please open an issue and it will probably
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.
### Almost sensible principles
- widely used settings that do not make it into the 'core'
- explicitly enabled with `set -g @almost-sensible 'on'`
### Goals ### Goals
- group standard tmux community options in one place - group standard tmux community options in one place
- 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
### Core options ### Options
# utf8 is on ```tmux
set -g utf8 on # Address vim mode switching delay (http://superuser.com/a/252717/65504)
set -g status-utf8 on set -s escape-time 0
# address vim mode switching delay (http://superuser.com/a/252717/65504) # Increase scrollback buffer size from 2000 to 50000 lines
set -s escape-time 0 set -g history-limit 50000
# increase scrollback buffer size # Increase tmux messages display duration from 750ms to 4s
set -g history-limit 50000 set -g display-time 4000
# tmux messages are displayed for 4 seconds # Refresh 'status-left' and 'status-right' more often, from every 15s to 5s
set -g display-time 4000 set -g status-interval 5
# refresh 'status-left' and 'status-right' more often # (OS X) Fix pbcopy/pbpaste for old tmux versions (pre 2.6)
set -g status-interval 5 set -g default-command "reattach-to-user-namespace -l $SHELL"
# set only on OS X where it's required # Upgrade $TERM
set -g default-command "reattach-to-user-namespace -l $SHELL" set -g default-terminal "screen-256color"
# upgrade $TERM # Emacs key bindings in tmux command prompt (prefix + :) are better than
set -g default-terminal "screen-256color" # vi keys, even for vim users
set -g status-keys emacs
# emacs key bindings in tmux command prompt (prefix + :) are better than # Focus events enabled for terminals that support them
# vi keys, even for vim users set -g focus-events on
set -g status-keys emacs
### Core key bindings # Super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on
```
# easier and faster switching between next/prev window ### Key bindings
bind C-p previous-window
bind C-n next-window ```tmux
# 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 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 allowing you to hold `Ctrl` and repeat `a + p`/`a + n` (if your prefix is
`C-a`), which is a lot quicker. `C-a`), which is a lot quicker.
# source .tmux.conf as suggested in `man tmux` ```tmux
bind R source-file '~/.tmux.conf' # Source .tmux.conf as suggested in `man tmux`
bind R source-file '~/.tmux.conf'
```
"Adaptable" key bindings that build upon your `prefix` value: "Adaptable" key bindings that build upon your `prefix` value:
# if prefix is 'C-a' ```tmux
bind C-a send-prefix # If prefix is 'C-a'
bind a last-window 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-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. If prefix is `C-z`, above keys will be `C-z` and `z`... you get the idea.
### Almost sensible options
Activate these by putting `set -g @almost-sensible 'on'` in `.tmux.conf`.
# C-a should be the Tmux default prefix, really
set -g prefix C-a
set -g mode-keys vi
# enable mouse features for terminals that support it
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
### 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 " \ ```tmux
tmux-plugins/tpm \ set -g @plugin '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!
You might also want to restart your tmux server, just in case.
### Manual Installation ### Manual Installation
Clone the repo: Clone the repo:
@ -109,14 +100,11 @@ Clone the repo:
Add this line to the bottom of `.tmux.conf`: Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/sensible.tmux ```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
@ -126,6 +114,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

View File

@ -2,13 +2,18 @@
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ALMOST_SENSIBLE_OPTION="@almost-sensible" # 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" ]
} }
iterm_terminal() {
[[ "${TERM_PROGRAM}" =~ ^iTerm || "${LC_TERMINAL}" =~ ^iTerm ]]
}
command_exists() { command_exists() {
local command="$1" local command="$1"
type "$command" >/dev/null 2>&1 type "$command" >/dev/null 2>&1
@ -40,8 +45,8 @@ server_option_value_not_changed() {
} }
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
@ -51,7 +56,7 @@ key_binding_not_set() {
key_binding_not_changed() { key_binding_not_changed() {
local key="$1" local key="$1"
local default_value="$2" local default_value="$2"
if $(tmux list-keys | grep -q "bind-key[[:space:]]\+${key}[[:space:]]\+${default_value}"); then if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
# key still has the default binding # key still has the default binding
return 0 return 0
else else
@ -59,19 +64,20 @@ key_binding_not_changed() {
fi fi
} }
almost_sensible_on() { get_tmux_config() {
[ "$(tmux show-option -gvq "$ALMOST_SENSIBLE_OPTION")" == "on" ] local tmux_config_xdg="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
local tmux_config="$HOME/.tmux.conf"
if [ -f "${tmux_config_xdg}" ]; then
echo "${tmux_config_xdg}"
else
echo ${tmux_config}
fi
} }
main() { main() {
# OPTIONS # OPTIONS
# enable utf8
tmux set-option -g utf8 on
# enable utf8 in tmux status-left and status-right
tmux set-option -g status-utf8 on
# 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
@ -97,26 +103,25 @@ main() {
tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL" 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+
if server_option_value_not_changed "default-terminal" "screen"; then
tmux set-option -s default-terminal "screen-256color"
fi
# 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
# ALMOST SENSIBLE OPTIONS # focus events enabled for terminals that support them
tmux set-option -g focus-events on
if almost_sensible_on; then # super useful when using "grouped sessions" and multi-monitor setup
# C-a should be the Tmux default prefix, really if ! iterm_terminal; then
tmux set-option -g prefix C-a tmux set-window-option -g aggressive-resize on
tmux set-option -g mode-keys vi
# enable mouse features for terminals that support it
tmux set-option -g mouse-resize-pane on
tmux set-option -g mouse-select-pane on
tmux set-option -g mouse-select-window on
fi fi
# DEFAULT KEY BINDINGS # DEFAULT KEY BINDINGS
@ -126,13 +131,15 @@ main() {
# if C-b is not prefix # if C-b is not prefix
if [ $prefix != "C-b" ]; then if [ $prefix != "C-b" ]; then
# unbind obsolte default binding # unbind obsolete default binding
if key_binding_not_changed "C-b" "send-prefix"; then if key_binding_not_changed "C-b" "send-prefix"; then
tmux unbind-key C-b tmux unbind-key C-b
fi fi
# pressing `prefix + prefix` sends <prefix> to the shell # pressing `prefix + prefix` sends <prefix> to the shell
tmux bind-key "$prefix" send-prefix if key_binding_not_set "$prefix"; then
tmux bind-key "$prefix" send-prefix
fi
fi fi
# If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows. # If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows.
@ -151,9 +158,11 @@ 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 ' \ local tmux_config=$(get_tmux_config)
tmux source-file ~/.tmux.conf > /dev/null; \
tmux display-message "Sourced .tmux.conf!"' tmux bind-key R run-shell " \
tmux source-file ${tmux_config} > /dev/null; \
tmux display-message 'Sourced ${tmux_config}!'"
fi fi
} }
main main