diff --git a/bindings/update_plugins b/bindings/update_plugins index 28cc281..8b3ca63 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" +source "$SCRIPTS_DIR/tmux_cmd_path.sh" + 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..2e342fa 100755 --- a/scripts/check_tmux_version.sh +++ b/scripts/check_tmux_version.sh @@ -3,10 +3,17 @@ 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" + + 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 @@ -30,13 +37,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: @@ -49,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_echo_functions.sh b/scripts/helpers/tmux_echo_functions.sh index 7a6ef0a..8bf6aa0 100644 --- a/scripts/helpers/tmux_echo_functions.sh +++ b/scripts/helpers/tmux_echo_functions.sh @@ -1,10 +1,15 @@ +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() { - $(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/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/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 7ad4b99..cadad42 100755 --- a/tpm +++ b/tpm @@ -4,12 +4,14 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BINDINGS_DIR="$CURRENT_DIR/bindings" SCRIPTS_DIR="$CURRENT_DIR/scripts" +source "$SCRIPTS_DIR/tmux_cmd_path.sh" + 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 @@ -18,7 +20,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 +33,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. @@ -58,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() {