From e1ba5e6337c9ccc2521fc96b21a2e7bce100f0c4 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 16:46:30 -0600 Subject: [PATCH 1/7] Remove unused UNSUPPORTED_MSG --- scripts/check_tmux_version.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index b0aedec..5e76a26 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash VERSION="$1" -UNSUPPORTED_MSG="$2" get_tmux_option() { local option=$1 @@ -54,11 +53,7 @@ tmux_version_int() { } 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 + echo "Error, Tmux version unsupported! Please install Tmux version $SUPPORTED_VERSION or greater!" } exit_if_unsupported_version() { From e998536be9008611a423953c11e07617b9179f50 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 16:53:09 -0600 Subject: [PATCH 2/7] Use SUPPORTED_VERSION from variables.sh --- scripts/check_tmux_version.sh | 6 ++++-- scripts/shared.sh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 5e76a26..e27d1c8 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -VERSION="$1" +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/variables.sh" get_tmux_option() { local option=$1 @@ -66,7 +68,7 @@ exit_if_unsupported_version() { } main() { - local supported_version_int="$(get_digits_from_string "$VERSION")" + local supported_version_int="$(get_digits_from_string "$SUPPORTED_VERSION")" local current_version_int="$(tmux_version_int)" exit_if_unsupported_version "$current_version_int" "$supported_version_int" } 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 From a9227d2791835836a2eeb13de9f443ed1791c6dd Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 16:55:07 -0600 Subject: [PATCH 3/7] Use get_tmux_option and display_message from shared.sh --- scripts/check_tmux_version.sh | 37 +---------------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index e27d1c8..65348b3 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -3,42 +3,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$CURRENT_DIR/variables.sh" - -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/shared.sh" # this is used to get "clean" integer version number. Examples: # `tmux 1.9` => `19` From 8b8a5b169941025712ec1c8c14b54d822c8c8c78 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 17:01:39 -0600 Subject: [PATCH 4/7] Simplify get_digits_from_string --- scripts/check_tmux_version.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 65348b3..678ee82 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -9,9 +9,7 @@ source "$CURRENT_DIR/shared.sh" # `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() { From ebfb274e111f7d944d8fd74b775cdfd4fb8d9fc9 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 17:04:08 -0600 Subject: [PATCH 5/7] Simplify and inline tmux_version_int --- scripts/check_tmux_version.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 678ee82..9227ebf 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -12,11 +12,6 @@ get_digits_from_string() { 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() { echo "Error, Tmux version unsupported! Please install Tmux version $SUPPORTED_VERSION or greater!" } @@ -32,7 +27,7 @@ exit_if_unsupported_version() { main() { local supported_version_int="$(get_digits_from_string "$SUPPORTED_VERSION")" - local current_version_int="$(tmux_version_int)" + local current_version_int="$(get_digits_from_string "$(tmux -V)")" exit_if_unsupported_version "$current_version_int" "$supported_version_int" } main From d635fb8957aea12b4ebde8a566e9ff5fdb495430 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 17:07:03 -0600 Subject: [PATCH 6/7] Inline exit_if_unsupported_version --- scripts/check_tmux_version.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 9227ebf..4b5889b 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -16,18 +16,12 @@ unsupported_version_message() { echo "Error, Tmux version unsupported! Please install Tmux version $SUPPORTED_VERSION or greater!" } -exit_if_unsupported_version() { - local current_version="$1" - local supported_version="$2" - if [ "$current_version" -lt "$supported_version" ]; then - display_message "$(unsupported_version_message)" - exit 1 - fi -} - main() { local supported_version_int="$(get_digits_from_string "$SUPPORTED_VERSION")" local current_version_int="$(get_digits_from_string "$(tmux -V)")" - exit_if_unsupported_version "$current_version_int" "$supported_version_int" + if [ "$current_version_int" -lt "$supported_version_int" ]; then + display_message "$(unsupported_version_message)" + exit 1 + fi } main From d715402d26df94e7a9da488317164b52e2757345 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 1 Mar 2025 17:08:40 -0600 Subject: [PATCH 7/7] Inline unsupported_version_message --- scripts/check_tmux_version.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 4b5889b..f257936 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -12,15 +12,11 @@ get_digits_from_string() { echo "$1" | tr -dC '[:digit:]' } -unsupported_version_message() { - echo "Error, Tmux version unsupported! Please install Tmux version $SUPPORTED_VERSION or greater!" -} - 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 "$(unsupported_version_message)" + display_message "Error, Tmux version unsupported! Please install Tmux version $SUPPORTED_VERSION or greater!" exit 1 fi }