diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index b0aedec..f257936 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -1,78 +1,23 @@ #!/usr/bin/env bash -VERSION="$1" -UNSUPPORTED_MSG="$2" +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -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" -} +source "$CURRENT_DIR/variables.sh" +source "$CURRENT_DIR/shared.sh" # this is used to get "clean" integer version number. Examples: # `tmux 1.9` => `19` # `1.9a` => `19` get_digits_from_string() { - local string="$1" - local only_digits="$(echo "$string" | tr -dC '[:digit:]')" - echo "$only_digits" + echo "$1" | tr -dC '[:digit:]' } -tmux_version_int() { - local tmux_version_string=$(tmux -V) - echo "$(get_digits_from_string "$tmux_version_string")" -} - -unsupported_version_message() { - if [ -n "$UNSUPPORTED_MSG" ]; then - echo "$UNSUPPORTED_MSG" - else - echo "Error, Tmux version unsupported! Please install Tmux version $VERSION or greater!" - fi -} - -exit_if_unsupported_version() { - local current_version="$1" - local supported_version="$2" - if [ "$current_version" -lt "$supported_version" ]; then - display_message "$(unsupported_version_message)" +main() { + local supported_version_int="$(get_digits_from_string "$SUPPORTED_VERSION")" + local current_version_int="$(get_digits_from_string "$(tmux -V)")" + if [ "$current_version_int" -lt "$supported_version_int" ]; then + display_message "Error, Tmux version unsupported! Please install Tmux version $SUPPORTED_VERSION or greater!" exit 1 fi } - -main() { - local supported_version_int="$(get_digits_from_string "$VERSION")" - local current_version_int="$(tmux_version_int)" - exit_if_unsupported_version "$current_version_int" "$supported_version_int" -} main diff --git a/scripts/shared.sh b/scripts/shared.sh index 8b316d1..90f6c0a 100644 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -41,7 +41,7 @@ remove_empty_lines_from_end_of_file() { } supported_tmux_version_ok() { - $CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION" + $CURRENT_DIR/check_tmux_version.sh } # Checking full path to logfile and expanding tmux format in normal path