From 7ce03269169f574ca4c1111a1aba2fb3b6acfaf5 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 7 Jul 2015 01:04:26 +0200 Subject: [PATCH] New and old plugin syntax work together --- CHANGELOG.md | 2 ++ scripts/shared_functions.sh | 20 +++++++++++--------- tests/test_plugin_installation_legacy.sh | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f16e0b..646b7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - revert back to using `-g` flag in new plugin definition syntax - permit leading whitespace with new plugin definition syntax (thanks @chilicuil) - make sure `TMUX_PLUGIN_MANAGER_PATH` always has trailng slash +- ensure old/deprecated plugin syntax `set -g @tpm_plugins` works alongside new + `set -g @plugin` syntax ### v1.2.2, 2015-02-08 - set GIT_TERMINAL_PROMPT=0 when doing `git clone`, `pull` or `submodule update` diff --git a/scripts/shared_functions.sh b/scripts/shared_functions.sh index 05ee2de..cd11ca5 100644 --- a/scripts/shared_functions.sh +++ b/scripts/shared_functions.sh @@ -1,5 +1,6 @@ # shared functions and constants +# using @tpm_plugins is now deprecated in favor of using @plugin syntax tpm_plugins_variable_name="@tpm_plugins" SHARED_TPM_PATH="" @@ -11,16 +12,17 @@ shared_set_tpm_path_constant() { SHARED_TPM_PATH="$(echo "$string_path" | sed "s,^\$HOME,$HOME," | sed "s,^~,$HOME,")" } +_tmux_conf_contents() { + cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null +} + shared_get_tpm_plugins_list() { - local plugins_list - plugins_list="$(tmux show-option -gqv "$tpm_plugins_variable_name")" - if [ -z "${plugins_list}" ]; then - #read set -g @plugin "tmux-plugins/tmux-example-plugin" entries - cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null | - awk '/^ *set +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }' - else - printf "%s\\n" "${plugins_list}" - fi + # DEPRECATED: lists plugins from @tpm_plugins option + echo "$(tmux show-option -gqv "$tpm_plugins_variable_name")" + + # read set -g @plugin "tmux-plugins/tmux-example-plugin" entries + _tmux_conf_contents | + awk '/^ *set +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }' } # Allowed plugin name formats: diff --git a/tests/test_plugin_installation_legacy.sh b/tests/test_plugin_installation_legacy.sh index fb9de71..6627b85 100755 --- a/tests/test_plugin_installation_legacy.sh +++ b/tests/test_plugin_installation_legacy.sh @@ -21,8 +21,32 @@ test_plugin_installation() { teardown_helper } +test_legacy_and_new_syntax_for_plugin_installation_work() { + set_tmux_conf_helper <<- HERE + set -g @tpm_plugins " \ + tmux-plugins/tmux-example-plugin \ + " + set -g @plugin 'tmux-plugins/tmux-copycat' + run-shell "$PWD/tpm" + HERE + + # opens tmux and test it with `expect` + "$CURRENT_DIR"/expect_successful_multiple_plugins_download || + fail_helper "Tmux multiple plugins installation fails" + + # check plugin dir exists after download + check_dir_exists_helper "$HOME/.tmux/plugins/tmux-example-plugin/" || + fail_helper "Plugin download fails (tmux-example-plugin)" + + check_dir_exists_helper "$HOME/.tmux/plugins/tmux-copycat/" || + fail_helper "Plugin download fails (tmux-copycat)" + + teardown_helper +} + main() { test_plugin_installation + test_legacy_and_new_syntax_for_plugin_installation_work exit_value_helper } main