diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e8d23..34c5966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - refactor test `expect` scripts, make them simpler and ensure they properly assert expectations - refactor code that sets 'TMUX_PLUGIN_MANAGER_PATH' global env var +- stop using global variable for 'tpm path' ### v2.0.0, 2015-07-07 - enable overriding default key bindings diff --git a/bindings/update_plugins b/bindings/update_plugins index 9a3a86c..3ee16ec 100755 --- a/bindings/update_plugins +++ b/bindings/update_plugins @@ -43,7 +43,6 @@ update_plugin_prompt() { main() { reload_tmux_environment - shared_set_tpm_path_constant display_plugin_update_list update_plugin_prompt } diff --git a/scripts/clean_plugins.sh b/scripts/clean_plugins.sh index 4ff59f6..6716271 100755 --- a/scripts/clean_plugins.sh +++ b/scripts/clean_plugins.sh @@ -15,7 +15,7 @@ clean_plugins() { local plugins plugin plugin_directory plugins="$(shared_get_tpm_plugins_list)" - for plugin_directory in "$SHARED_TPM_PATH"/*; do + for plugin_directory in "$(tpm_path)"/*; do [ -d "${plugin_directory}" ] || continue plugin="$(shared_plugin_name "${plugin_directory}")" case "${plugins}" in @@ -33,7 +33,6 @@ clean_plugins() { } main() { - shared_set_tpm_path_constant ensure_tpm_path_exists clean_plugins exit_value_helper diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index be7cd5b..f143940 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -13,7 +13,7 @@ fi clone() { local plugin="$1" - cd "$SHARED_TPM_PATH" && + cd "$(tpm_path)" && GIT_TERMINAL_PROMPT=0 git clone --recursive "$plugin" >/dev/null 2>&1 } @@ -49,14 +49,14 @@ install_plugins() { } verify_tpm_path_permissions() { + local path="$(tpm_path)" # check the write permission flag for all users to ensure # that we have proper access - [ -w "$SHARED_TPM_PATH" ] || - echo_err "$SHARED_TPM_PATH is not writable!" + [ -w "$path" ] || + echo_err "$path is not writable!" } main() { - shared_set_tpm_path_constant ensure_tpm_path_exists verify_tpm_path_permissions install_plugins diff --git a/scripts/shared_functions.sh b/scripts/shared_functions.sh index 878e73a..4e429b1 100644 --- a/scripts/shared_functions.sh +++ b/scripts/shared_functions.sh @@ -2,14 +2,18 @@ # using @tpm_plugins is now deprecated in favor of using @plugin syntax tpm_plugins_variable_name="@tpm_plugins" -SHARED_TPM_PATH="" -# sets a "global variable" for the current file -shared_set_tpm_path_constant() { +_tpm_path() { local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" # manually expanding tilde or `$HOME` variable. string_path="${string_path/#\~/$HOME}" - SHARED_TPM_PATH="${string_path/#\$HOME/$HOME}" + echo "${string_path/#\$HOME/$HOME}" +} + +_CACHED_TPM_PATH="$(_tpm_path)" + +tpm_path() { + echo "$_CACHED_TPM_PATH" } _tmux_conf_contents() { @@ -40,7 +44,7 @@ shared_plugin_name() { shared_plugin_path() { local plugin="$1" local plugin_name="$(shared_plugin_name "$plugin")" - echo "${SHARED_TPM_PATH}${plugin_name}/" + echo "$(tpm_path)${plugin_name}/" } plugin_already_installed() { @@ -52,7 +56,7 @@ plugin_already_installed() { } ensure_tpm_path_exists() { - mkdir -p "$SHARED_TPM_PATH" + mkdir -p "$(tpm_path)" } fail_helper() { diff --git a/scripts/source_plugins.sh b/scripts/source_plugins.sh index 4d79b18..8a6715b 100755 --- a/scripts/source_plugins.sh +++ b/scripts/source_plugins.sh @@ -35,7 +35,6 @@ source_plugins() { } main() { - shared_set_tpm_path_constant source_plugins } main diff --git a/scripts/update_plugin.sh b/scripts/update_plugin.sh index 4407102..ec47614 100755 --- a/scripts/update_plugin.sh +++ b/scripts/update_plugin.sh @@ -58,7 +58,6 @@ update_plugins() { } main() { - shared_set_tpm_path_constant if [ "$1" == "all" ]; then update_all else