From d565659d4608b4953c2c08d9cf092201d382db36 Mon Sep 17 00:00:00 2001 From: michaellee8 Date: Sun, 15 Nov 2020 15:49:39 +0000 Subject: [PATCH 1/4] fix: add TMUX_CMD_PATH to handle the case of multiple tmux installation --- bindings/update_plugins | 4 +++- scripts/check_tmux_version.sh | 8 +++++--- tpm | 10 ++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bindings/update_plugins b/bindings/update_plugins index 28cc281..ce3df46 100755 --- a/bindings/update_plugins +++ b/bindings/update_plugins @@ -11,6 +11,8 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPTS_DIR="$CURRENT_DIR/../scripts" HELPERS_DIR="$SCRIPTS_DIR/helpers" +export TMUX_CMD_PATH=$(realpath "/proc/$(tmux display -p '#{pid}')/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') + source "$HELPERS_DIR/plugin_functions.sh" source "$HELPERS_DIR/tmux_echo_functions.sh" source "$HELPERS_DIR/tmux_utils.sh" @@ -36,7 +38,7 @@ display_plugin_update_list() { } update_plugin_prompt() { - tmux command-prompt -p 'plugin update:' " \ + $TMUX_CMD_PATH command-prompt -p 'plugin update:' " \ send-keys C-c; \ run-shell '$SCRIPTS_DIR/update_plugin_prompt_handler.sh %1'" } diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index b0aedec..77901b4 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -3,6 +3,8 @@ VERSION="$1" UNSUPPORTED_MSG="$2" +export TMUX_CMD_PATH=$(realpath "/proc/$(tmux display -p '#{pid}')/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') + get_tmux_option() { local option=$1 local default_value=$2 @@ -30,13 +32,13 @@ display_message() { 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" + $TMUX_CMD_PATH set-option -gq display-time "$display_duration" # displays message - tmux display-message "$message" + $TMUX_CMD_PATH display-message "$message" # restores original 'display-time' value - tmux set-option -gq display-time "$saved_display_time" + $TMUX_CMD_PATH set-option -gq display-time "$saved_display_time" } # this is used to get "clean" integer version number. Examples: diff --git a/tpm b/tpm index 7ad4b99..a96b4b0 100755 --- a/tpm +++ b/tpm @@ -4,6 +4,12 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BINDINGS_DIR="$CURRENT_DIR/bindings" SCRIPTS_DIR="$CURRENT_DIR/scripts" +# Try to find the executable path of the currently running +# tmux server, fallback to just "tmux" if not found or no +# procfs aviliable (non-linux). +export TMUX_CMD_PATH=$(realpath "/proc/$(tmux display -p '#{pid}')/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') +echo "tmux executable used: $TMUX_CMD_PATH" + source "$SCRIPTS_DIR/variables.sh" get_tmux_option() { @@ -18,7 +24,7 @@ get_tmux_option() { } tpm_path_set() { - tmux show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1 + $TMUX_CMD_PATH show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1 } # Check if configuration file exists at an XDG-compatible location, if so use @@ -31,7 +37,7 @@ set_default_tpm_path() { tpm_path="$xdg_tmux_path/plugins/" fi - tmux set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$tpm_path" + $TMUX_CMD_PATH set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$tpm_path" } # Ensures TMUX_PLUGIN_MANAGER_PATH global env variable is set. From f8044dbe23af97a178bc2c44899679c23c04d11f Mon Sep 17 00:00:00 2001 From: michaellee8 Date: Mon, 16 Nov 2020 05:47:56 +0000 Subject: [PATCH 2/4] fix: use an alternate method to get TMUX_CMD_PATH --- bindings/update_plugins | 2 +- scripts/check_tmux_version.sh | 3 ++- scripts/helpers/tmux_echo_functions.sh | 6 ++++-- scripts/tmux_cmd_path.sh | 18 ++++++++++++++++++ tpm | 6 +----- 5 files changed, 26 insertions(+), 9 deletions(-) create mode 100755 scripts/tmux_cmd_path.sh diff --git a/bindings/update_plugins b/bindings/update_plugins index ce3df46..8b3ca63 100755 --- a/bindings/update_plugins +++ b/bindings/update_plugins @@ -11,7 +11,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPTS_DIR="$CURRENT_DIR/../scripts" HELPERS_DIR="$SCRIPTS_DIR/helpers" -export TMUX_CMD_PATH=$(realpath "/proc/$(tmux display -p '#{pid}')/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') +source "$SCRIPTS_DIR/tmux_cmd_path.sh" source "$HELPERS_DIR/plugin_functions.sh" source "$HELPERS_DIR/tmux_echo_functions.sh" diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 77901b4..0774d7f 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -3,7 +3,8 @@ VERSION="$1" UNSUPPORTED_MSG="$2" -export TMUX_CMD_PATH=$(realpath "/proc/$(tmux display -p '#{pid}')/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') +source "$SCRIPTS_DIR/tmux_cmd_path.sh" + get_tmux_option() { local option=$1 diff --git a/scripts/helpers/tmux_echo_functions.sh b/scripts/helpers/tmux_echo_functions.sh index 7a6ef0a..989b876 100644 --- a/scripts/helpers/tmux_echo_functions.sh +++ b/scripts/helpers/tmux_echo_functions.sh @@ -1,10 +1,12 @@ +source "$SCRIPTS_DIR/tmux_cmd_path.sh" + _has_emacs_mode_keys() { - $(tmux show -gw mode-keys | grep -q emacs) + $($TMUX_CMD_PATH show -gw mode-keys | grep -q emacs) } tmux_echo() { local message="$1" - tmux run-shell "echo '$message'" + $TMUX_CMD_PATH run-shell "echo '$message'" } echo_ok() { diff --git a/scripts/tmux_cmd_path.sh b/scripts/tmux_cmd_path.sh new file mode 100755 index 0000000..60fd2e4 --- /dev/null +++ b/scripts/tmux_cmd_path.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Written by michaellee8 in Nov 2020 for +# https://github.com/tmux-plugins/tpm/issues/189 to prevent problems caused by +# tmux version mismatch between client and server. This script is +# licensed in public domain. + +# Try to get the process ID of the running tmux server, +# would be empty if not found +TMUX_SERVER_PID=$(ps -eo pid=,comm= | grep 'tmux: server' | awk '{ print $1; }') + +if [[ -n "$TMUX_SERVER_PID" ]]; then + TMUX_CMD_PATH=$(realpath "/proc/$TMUX_SERVER_PID/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') +else + TMUX_CMD_PATH='tmux' +fi + +export TMUX_CMD_PATH diff --git a/tpm b/tpm index a96b4b0..e8d79d5 100755 --- a/tpm +++ b/tpm @@ -4,11 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BINDINGS_DIR="$CURRENT_DIR/bindings" SCRIPTS_DIR="$CURRENT_DIR/scripts" -# Try to find the executable path of the currently running -# tmux server, fallback to just "tmux" if not found or no -# procfs aviliable (non-linux). -export TMUX_CMD_PATH=$(realpath "/proc/$(tmux display -p '#{pid}')/exe" 2> /dev/null || echo "tmux" | sed -z '$ s/\n$//') -echo "tmux executable used: $TMUX_CMD_PATH" +source "$SCRIPTS_DIR/tmux_cmd_path.sh" source "$SCRIPTS_DIR/variables.sh" From 74a45912c4dfdfc6663c157f46224d7532a6704d Mon Sep 17 00:00:00 2001 From: michaellee8 Date: Mon, 16 Nov 2020 06:41:13 +0000 Subject: [PATCH 3/4] fix: ensure SCRIPT_DIR exists --- scripts/check_tmux_version.sh | 4 ++++ scripts/helpers/tmux_echo_functions.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index 0774d7f..f5db448 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -3,6 +3,10 @@ VERSION="$1" UNSUPPORTED_MSG="$2" +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SCRIPTS_DIR="$CURRENT_DIR/../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" + source "$SCRIPTS_DIR/tmux_cmd_path.sh" diff --git a/scripts/helpers/tmux_echo_functions.sh b/scripts/helpers/tmux_echo_functions.sh index 989b876..8bf6aa0 100644 --- a/scripts/helpers/tmux_echo_functions.sh +++ b/scripts/helpers/tmux_echo_functions.sh @@ -1,3 +1,6 @@ +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SCRIPTS_DIR="$CURRENT_DIR/../../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" source "$SCRIPTS_DIR/tmux_cmd_path.sh" _has_emacs_mode_keys() { From 3206dec40bdcc2f6a3a9c1b46dacaca8cd39a2d3 Mon Sep 17 00:00:00 2001 From: michaellee8 Date: Mon, 16 Nov 2020 08:00:36 +0000 Subject: [PATCH 4/4] fix: change more "tmux" to use TMUX_CMD_PATH --- scripts/check_tmux_version.sh | 4 ++-- scripts/helpers/plugin_functions.sh | 7 ++++++- scripts/helpers/tmux_utils.sh | 8 +++++++- tpm | 8 ++++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/check_tmux_version.sh b/scripts/check_tmux_version.sh index f5db448..2e342fa 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -13,7 +13,7 @@ source "$SCRIPTS_DIR/tmux_cmd_path.sh" get_tmux_option() { local option=$1 local default_value=$2 - local option_value=$(tmux show-option -gqv "$option") + local option_value=$($TMUX_CMD_PATH show-option -gqv "$option") if [ -z "$option_value" ]; then echo "$default_value" else @@ -56,7 +56,7 @@ get_digits_from_string() { } tmux_version_int() { - local tmux_version_string=$(tmux -V) + local tmux_version_string=$($TMUX_CMD_PATH -V) echo "$(get_digits_from_string "$tmux_version_string")" } diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index f33d215..b249cee 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -1,6 +1,11 @@ # using @tpm_plugins is now deprecated in favor of using @plugin syntax tpm_plugins_variable_name="@tpm_plugins" +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SCRIPTS_DIR="$CURRENT_DIR/../../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" +source "$SCRIPTS_DIR/tmux_cmd_path.sh" + # manually expanding tilde char or `$HOME` variable. _manual_expansion() { local path="$1" @@ -9,7 +14,7 @@ _manual_expansion() { } _tpm_path() { - local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" + local string_path="$($TMUX_CMD_PATH start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" _manual_expansion "$string_path" } diff --git a/scripts/helpers/tmux_utils.sh b/scripts/helpers/tmux_utils.sh index e39946a..778e29e 100644 --- a/scripts/helpers/tmux_utils.sh +++ b/scripts/helpers/tmux_utils.sh @@ -1,3 +1,9 @@ + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SCRIPTS_DIR="$CURRENT_DIR/../../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" +source "$SCRIPTS_DIR/tmux_cmd_path.sh" + reload_tmux_environment() { - tmux source-file ~/.tmux.conf >/dev/null 2>&1 + $TMUX_CMD_PATH source-file ~/.tmux.conf >/dev/null 2>&1 } diff --git a/tpm b/tpm index e8d79d5..cadad42 100755 --- a/tpm +++ b/tpm @@ -11,7 +11,7 @@ source "$SCRIPTS_DIR/variables.sh" get_tmux_option() { local option="$1" local default_value="$2" - local option_value="$(tmux show-option -gqv "$option")" + local option_value="$($TMUX_CMD_PATH show-option -gqv "$option")" if [ -z "$option_value" ]; then echo "$default_value" else @@ -60,13 +60,13 @@ source_plugins() { # prefix + alt + u - remove unused TPM plugins and reloads TMUX environment set_tpm_key_bindings() { local install_key="$(get_tmux_option "$install_key_option" "$default_install_key")" - tmux bind-key "$install_key" run-shell "$BINDINGS_DIR/install_plugins" + $TMUX_CMD_PATH bind-key "$install_key" run-shell "$BINDINGS_DIR/install_plugins" local update_key="$(get_tmux_option "$update_key_option" "$default_update_key")" - tmux bind-key "$update_key" run-shell "$BINDINGS_DIR/update_plugins" + $TMUX_CMD_PATH bind-key "$update_key" run-shell "$BINDINGS_DIR/update_plugins" local clean_key="$(get_tmux_option "$clean_key_option" "$default_clean_key")" - tmux bind-key "$clean_key" run-shell "$BINDINGS_DIR/clean_plugins" + $TMUX_CMD_PATH bind-key "$clean_key" run-shell "$BINDINGS_DIR/clean_plugins" } supported_tmux_version_ok() {