Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add TMUX_CMD_PATH to handle the case of multiple tmux installation #190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bindings/update_plugins
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'"
}
Expand Down
17 changes: 12 additions & 5 deletions scripts/check_tmux_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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")"
}

Expand Down
7 changes: 6 additions & 1 deletion scripts/helpers/plugin_functions.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}

Expand Down
9 changes: 7 additions & 2 deletions scripts/helpers/tmux_echo_functions.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
8 changes: 7 additions & 1 deletion scripts/helpers/tmux_utils.sh
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions scripts/tmux_cmd_path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Written by michaellee8 <[email protected]> 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
14 changes: 8 additions & 6 deletions tpm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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() {
Expand Down