Create plugin start script

This commit is contained in:
Bruno Sutic 2014-08-25 22:29:03 +02:00
parent 85e45f8d2c
commit 651b14075a
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
2 changed files with 68 additions and 0 deletions

35
scripts/helpers.sh Normal file
View File

@ -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"
}

33
session_saver.tmux Normal file → Executable file
View File

@ -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