From 2d5ecdbe4a958233050c88a4238a66ea8b21dcec Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Tue, 26 May 2015 22:46:15 -0500 Subject: [PATCH] add removal procedure --- scripts/clean_plugins.sh | 44 +++++++++++++++++++++++++++ scripts/variables.sh | 3 ++ tests/expect_successful_clean_plugins | 30 ++++++++++++++++++ tests/test_plugin_clean.sh | 32 +++++++++++++++++++ tpm | 4 +++ 5 files changed, 113 insertions(+) create mode 100755 scripts/clean_plugins.sh create mode 100755 tests/expect_successful_clean_plugins create mode 100755 tests/test_plugin_clean.sh diff --git a/scripts/clean_plugins.sh b/scripts/clean_plugins.sh new file mode 100755 index 0000000..84ba48b --- /dev/null +++ b/scripts/clean_plugins.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/shared_functions.sh" + +clean_plugins() { + local plugins plugin plugin_directory + plugins="$(shared_get_tpm_plugins_list)" + + for plugin_directory in "$SHARED_TPM_PATH"/*; do + [ -d "${plugin_directory}" ] || continue + plugin="$(shared_plugin_name "${plugin_directory}")" + case "${plugins}" in + *"${plugin}"*) : ;; + *) + [ "${plugin}" = "tpm" ] && continue + echo_message "Removing \"$plugin\"" + rm -rf "${plugin_directory}" + [ -d "${plugin_directory}" ] && + echo_message " \"$plugin\" clean fail" || + echo_message " \"$plugin\" clean success" + ;; + esac + done +} + +ensure_tpm_path_exists() { + mkdir -p "$SHARED_TPM_PATH" +} + +reload_tmux_environment() { + tmux source-file ~/.tmux.conf >/dev/null 2>&1 +} + +main() { + reload_tmux_environment + shared_set_tpm_path_constant + ensure_tpm_path_exists + clean_plugins + reload_tmux_environment + end_message +} +main diff --git a/scripts/variables.sh b/scripts/variables.sh index c50984a..f79feb7 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -3,3 +3,6 @@ default_install_key="I" update_key_option="@tpm-update" default_update_key="U" + +clean_key_option="@tpm-clean" +default_clean_key="Y" diff --git a/tests/expect_successful_clean_plugins b/tests/expect_successful_clean_plugins new file mode 100755 index 0000000..92a01d5 --- /dev/null +++ b/tests/expect_successful_clean_plugins @@ -0,0 +1,30 @@ +#!/usr/bin/env expect + +# disables script output +log_user 0 + +spawn tmux + +# Waiting for tmux to attach. If this is not done, next command, `send` will +# not work properly. +sleep 1 + +# this is tmux prefix + U +send "Y" + +set timeout 5 + +expect { + "Removing \"tmux-example-plugin\"" { + expect { + "\"tmux-example-plugin\" clean success" { + expect { "Done, press ENTER to continue." { exit 0 } } + } + } + } + + timeout { + puts "Plugin update prompt timeout"; + exit 1 + } +} diff --git a/tests/test_plugin_clean.sh b/tests/test_plugin_clean.sh new file mode 100755 index 0000000..3d579a0 --- /dev/null +++ b/tests/test_plugin_clean.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR"/helpers.sh + +manually_install_the_plugin() { + rm -rf ~/.tmux/plugins/ + mkdir -p ~/.tmux/plugins/ + cd ~/.tmux/plugins/ + git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin +} + +test_plugin_installation() { + set_tmux_conf_helper <<- HERE + run-shell "$PWD/tpm" + HERE + + manually_install_the_plugin + + # opens tmux and test it with `expect` + "$CURRENT_DIR"/expect_successful_clean_plugins || + fail_helper "Clean fails" + + teardown_helper +} + +main() { + test_plugin_installation + exit_value_helper +} +main diff --git a/tpm b/tpm index b12899f..7fd0b55 100755 --- a/tpm +++ b/tpm @@ -28,12 +28,16 @@ source_plugins() { # prefix + I - downloads TPM plugins and reloads TMUX environment # prefix + U - updates a plugin (or all of them) and reloads TMUX environment +# prefix + Y - 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 "$CURRENT_DIR/scripts/install_plugins.sh >/dev/null 2>&1" local update_key=$(get_tmux_option "$update_key_option" "$default_update_key") tmux bind-key "$update_key" run-shell "$CURRENT_DIR/scripts/update_plugin_prompt.sh" + + local clean_key=$(get_tmux_option "$clean_key_option" "$default_clean_key") + tmux bind-key "$clean_key" run-shell "$CURRENT_DIR/scripts/clean_plugins.sh" } supported_tmux_version_ok() {