From 2ef7b79dda694c162c3a4289a7da9bc1fdc45846 Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Wed, 27 May 2015 14:27:01 -0500 Subject: [PATCH] add bundle style plugin definition --- scripts/shared_functions.sh | 16 +++++++++++--- tests/test_plugin_bundle_installation.sh | 28 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 tests/test_plugin_bundle_installation.sh diff --git a/scripts/shared_functions.sh b/scripts/shared_functions.sh index efa9e89..edfb524 100644 --- a/scripts/shared_functions.sh +++ b/scripts/shared_functions.sh @@ -5,14 +5,24 @@ SHARED_TPM_PATH="" # sets a "global variable" for the current file shared_set_tpm_path_constant() { - local string_path="$(tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)" + #local string_path="$(tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)" + #pipes(due to fork) are expensive, the less the better + local string_path="$(tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH)"; string_path="${string_path##*=}" # NOTE: manually expanding tilde or `$HOME` variable. Avoids using `eval` as # described here http://stackoverflow.com/a/5748307/777337 - SHARED_TPM_PATH="$(echo "$string_path" | sed "s,^\$HOME,$HOME," | sed "s,^~,$HOME,")" + SHARED_TPM_PATH="$(echo "$string_path" | sed "s,^\$HOME,$HOME,;s,^~,$HOME,;")" } shared_get_tpm_plugins_list() { - tmux show-option -gqv "$tpm_plugins_variable_name" + local plugins_list + plugins_list="$(tmux show-option -gqv "$tpm_plugins_variable_name")" + if [ -z "${plugins_list}" ]; then + #read set -g @bundle "tmux-plugins/tmux-example-plugin" entries + cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null | \ + awk '/set.*-g.*@[bB][uU][nN][dD][lL][eE]/ {if($1!~"^#"){gsub(/'\''/,"");gsub(/'\"'/,"");print $4}}' #recover vim syntax' + else + printf "%s\\n" "${plugins_list}" + fi } # Allowed plugin name formats: diff --git a/tests/test_plugin_bundle_installation.sh b/tests/test_plugin_bundle_installation.sh new file mode 100755 index 0000000..3156705 --- /dev/null +++ b/tests/test_plugin_bundle_installation.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source $CURRENT_DIR/helpers.sh + +test_plugin_installation() { + set_tmux_conf_helper <<- HERE + set -g @bUnDlE "tmux-plugins/tmux-example-plugin" + run-shell "$PWD/tpm" + HERE + + # opens tmux and test it with `expect` + "$CURRENT_DIR"/expect_successful_plugin_download || + fail_helper "Tmux plugin installation fails" + + # check plugin dir exists after download + check_dir_exists_helper "$HOME/.tmux/plugins/tmux-example-plugin/" || + fail_helper "Plugin download fails" + + teardown_helper +} + +main() { + test_plugin_installation + exit_value_helper +} +main