From 651b14075a2c6650ecc0ca37117cfee0403bdcd0 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Mon, 25 Aug 2014 22:29:03 +0200 Subject: [PATCH] Create plugin start script --- scripts/helpers.sh | 35 +++++++++++++++++++++++++++++++++++ session_saver.tmux | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 scripts/helpers.sh mode change 100644 => 100755 session_saver.tmux diff --git a/scripts/helpers.sh b/scripts/helpers.sh new file mode 100644 index 0000000..4850db0 --- /dev/null +++ b/scripts/helpers.sh @@ -0,0 +1,35 @@ +get_tmux_option() { + local option="$1" + local default_value="$2" + local option_value=$(tmux show-option -gqv "$option") + if [ -z "$option_value" ]; then + echo "$default_value" + else + echo "$option_value" + fi +} + +# Ensures a message is displayed for 5 seconds in tmux prompt. +# Does not override the 'display-time' tmux option. +display_message() { + local message="$1" + + # display_duration defaults to 5 seconds, if not passed as an argument + if [ "$#" -eq 2 ]; then + local display_duration="$2" + else + local display_duration="5000" + fi + + # saves user-set 'display-time' option + local saved_display_time=$(get_tmux_option "display-time" "750") + + # sets message display time to 5 seconds + tmux set-option -gq display-time "$display_duration" + + # displays message + tmux display-message "$message" + + # restores original 'display-time' value + tmux set-option -gq display-time "$saved_display_time" +} diff --git a/session_saver.tmux b/session_saver.tmux old mode 100644 new mode 100755 index e69de29..1f47d07 --- a/session_saver.tmux +++ b/session_saver.tmux @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/scripts/helpers.sh" + +default_save_key="M-s" +save_option="@session-saver-save" + +default_restore_key="M-r" +restore_option="@session-saver-restore" + +set_save_bindings() { + local key_bindings=$(get_tmux_option "$save_option" "$default_save_key") + local key + for key in $key_bindings; do + tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/session_saver.sh" + done +} + +set_restore_bindings() { + local key_bindings=$(get_tmux_option "$restore_option" "$default_restore_key") + local key + for key in $key_bindings; do + tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/session_restorer.sh" + done +} + +main() { + set_save_bindings + set_restore_bindings +} +main