From 7810165e88e0f2e6b6dba259e18a382c029e7f66 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Wed, 30 Jul 2014 16:33:51 +0200 Subject: [PATCH] First commit --- CHANGELOG.md | 0 LICENSE.md | 19 +++++++++ README.md | 0 sensible.tmux | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100755 sensible.tmux diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..40f6ddd --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (C) 2014 Bruno Sutic + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sensible.tmux b/sensible.tmux new file mode 100755 index 0000000..f8cbd99 --- /dev/null +++ b/sensible.tmux @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +is_osx() { + local platform=$(uname) + [ "$platform" == "Darwin" ] +} + +option_value_not_changed() { + local option="$1" + local default_value="$2" + local option_value=$(tmux show-option -gv "$option") + [ $option_value == $default_value ] +} + +server_option_value_not_changed() { + local option="$1" + local default_value="$2" + local option_value=$(tmux show-option -sv "$option") + [ $option_value == $default_value ] +} + +key_binding_not_set() { + local key="$1" + if $(tmux list-keys | grep -q "bind-key[[:space:]]\+${key}"); then + return 1 + else + return 0 + fi +} + +main() { + # 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 + + # 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 + fi + + # increase scrollback buffer size + if option_value_not_changed "history-limit" "2000"; then + tmux set-option -g history-limit 50000 + fi + + # tmux messages are displayed for 4 seconds + if option_value_not_changed "display-time" "750"; then + tmux set-option -g display-time 4000 + fi + + # refresh 'status-left' and 'status-right' more often + if option_value_not_changed "status-interval" "15"; then + tmux set-option -g status-interval 5 + fi + + # required (only) on OS X + if is_osx && option_value_not_changed "default-command" ""; then + tmux set-option -g default-command "reattach-to-user-namespace -l bash" + fi + + # upgrade $TERM + if option_value_not_changed "default-terminal" "screen"; then + tmux set-option -g default-terminal "screen-256color" + fi + + # 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 + + # 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 + fi + + # Ctrl-a + Ctrl-a switch between alternate windows + if key_binding_not_set "C-a"; then + tmux bind-key C-a last-window + fi + + # easier switching between next/prev window + if key_binding_not_set "C-p"; then + tmux bind-key C-p previous-window + fi + if key_binding_not_set "C-n"; then + tmux bind-key C-n next-window + fi + + # source `.tmux.conf` file - as suggested in `man tmux` + if key_binding_not_set "R"; then + tmux bind-key R run-shell -b ' \ + tmux source-file ~/.tmux.conf > /dev/null; \ + tmux display-message "Sourced .tmux.conf!"' + fi +} +main