From 89a51c86e33f500935de90158f2ac7887d832b34 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Mon, 4 Aug 2014 17:14:30 +0200 Subject: [PATCH] Do not force prefix to C-a Assuming no one uses C-b as the default prefix is a wrong assumption. Instead of making any assumption about the prefix, we're "building" on top of whatever the user has set. The following key-bindings will be set if prefix is set to C-a: - `C-a + C-a` - sends prefix character - `C-a + a` - switches to the last window Likewise, if C-b is prefix, then the additional bindings will be `C-b + C-b` and `C-b + b`. Closes #1 --- CHANGELOG.md | 1 + sensible.tmux | 37 +++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce1a462..df761a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### master - 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 ### v1.0.0, 2014-07-30 - initial work on the plugin diff --git a/sensible.tmux b/sensible.tmux index 13b766a..ae21f84 100755 --- a/sensible.tmux +++ b/sensible.tmux @@ -7,6 +7,17 @@ is_osx() { [ "$platform" == "Darwin" ] } +# 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() { local option="$1" local default_value="$2" @@ -39,12 +50,6 @@ main() { # enable utf8 in tmux status-left and status-right 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) if server_option_value_not_changed "escape-time" "500"; then tmux set-option -s escape-time 0 @@ -87,14 +92,22 @@ main() { # DEFAULT KEY BINDINGS - # Ctrl-a + a send `Ctrl-a` to the shell - if key_binding_not_set "a"; then - tmux bind-key a send-prefix + local prefix="$(prefix)" + local prefix_without_ctrl="$(prefix_without_ctrl)" + + # if C-b is not prefix + if [ $prefix != "C-b" ]; then + # unbind obsolte default binding + tmux unbind-key C-b + + # pressing `prefix + prefix` sends to the shell + tmux bind-key "$prefix" send-prefix fi - # Ctrl-a + Ctrl-a switch between alternate windows - if key_binding_not_set "C-a"; then - tmux bind-key C-a last-window + # If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows. + # Works for any prefix character. + if key_binding_not_set "$prefix_without_ctrl"; then + tmux bind-key "$prefix_without_ctrl" last-window fi # easier switching between next/prev window