tmux-resurrect/scripts/helpers.sh
2014-08-28 23:48:04 +02:00

67 lines
1.4 KiB
Bash

# configurable constants
default_sessions_dir="$HOME/.tmux/sessions"
sessions_dir_option="@session-saver-dir"
SUPPORTED_VERSION="1.9"
# helper functions
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"
}
supported_tmux_version_ok() {
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
}
remove_first_char() {
echo "$1" | cut -c2-
}
# path helpers
sessions_dir() {
echo $(get_tmux_option "$sessions_dir_option" "$default_sessions_dir")
}
session_path() {
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
echo "$(sessions_dir)/tmux_session_${timestamp}.txt"
}
last_session_path() {
echo "$(sessions_dir)/last"
}