Enable removing plugins via CLI executable
This commit is contained in:
parent
b2a2581a6a
commit
19da205b0b
7 changed files with 107 additions and 12 deletions
|
@ -61,7 +61,7 @@ find plugin directory there and remove it.
|
|||
- updates plugin(s)
|
||||
|
||||
`prefix + alt + u`
|
||||
- uninstall plugins that are not on the plugin list
|
||||
- remove/uninstall plugins not on the plugin list
|
||||
|
||||
### More plugins
|
||||
|
||||
|
|
14
bin/clean_plugins
Executable file
14
bin/clean_plugins
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Script intended for use via the command line.
|
||||
#
|
||||
# `.tmux.conf` needs to be set for TPM. Tmux has to be installed on the system,
|
||||
# but does not need to be started in order to run this script.
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
|
||||
|
||||
main() {
|
||||
"$SCRIPTS_DIR/clean_plugins.sh" # has correct exit code
|
||||
}
|
||||
main
|
17
bindings/clean_plugins
Executable file
17
bindings/clean_plugins
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Tmux key-binding script.
|
||||
# Scripts intended to be used via the command line are in `bin/` directory.
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
|
||||
|
||||
source "$SCRIPTS_DIR/shared_functions.sh"
|
||||
|
||||
main() {
|
||||
reload_tmux_environment
|
||||
"$SCRIPTS_DIR/clean_plugins.sh" --tmux-echo >/dev/null 2>&1
|
||||
reload_tmux_environment
|
||||
end_message
|
||||
}
|
||||
main
|
|
@ -28,3 +28,9 @@ To update all installed plugins:
|
|||
or update a single plugin:
|
||||
|
||||
~/.tmux/plugins/tpm/bin/install_plugins tmux-sensible
|
||||
|
||||
### Removing plugins
|
||||
|
||||
To remove plugins not on the plugin list:
|
||||
|
||||
~/.tmux/plugins/tpm/bin/clean_plugins
|
||||
|
|
|
@ -4,6 +4,33 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
|
||||
source "$CURRENT_DIR/shared_functions.sh"
|
||||
|
||||
TMUX_ECHO_FLAG="$1"
|
||||
|
||||
# True if invoked as tmux mapping or tmux command,
|
||||
# false if invoked via command line wrapper from `bin/` directory.
|
||||
use_tmux_echo() {
|
||||
[ "$TMUX_ECHO_FLAG" == "--tmux-echo" ]
|
||||
}
|
||||
|
||||
if use_tmux_echo; then
|
||||
# use tmux specific echo-ing
|
||||
echo_ok() {
|
||||
echo_message "$*"
|
||||
}
|
||||
|
||||
echo_err() {
|
||||
echo_message "$*"
|
||||
}
|
||||
else
|
||||
echo_ok() {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
echo_err() {
|
||||
fail_helper "$*"
|
||||
}
|
||||
fi
|
||||
|
||||
clean_plugins() {
|
||||
local plugins plugin plugin_directory
|
||||
plugins="$(shared_get_tpm_plugins_list)"
|
||||
|
@ -15,22 +42,20 @@ clean_plugins() {
|
|||
*"${plugin}"*) : ;;
|
||||
*)
|
||||
[ "${plugin}" = "tpm" ] && continue
|
||||
echo_message "Removing \"$plugin\""
|
||||
rm -rf "${plugin_directory}"
|
||||
echo_ok "Removing \"$plugin\""
|
||||
rm -rf "${plugin_directory}" >/dev/null 2>&1
|
||||
[ -d "${plugin_directory}" ] &&
|
||||
echo_message " \"$plugin\" clean fail" ||
|
||||
echo_message " \"$plugin\" clean success"
|
||||
echo_err " \"$plugin\" clean fail" ||
|
||||
echo_ok " \"$plugin\" clean success"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
reload_tmux_environment
|
||||
shared_set_tpm_path_constant
|
||||
ensure_tpm_path_exists
|
||||
clean_plugins
|
||||
reload_tmux_environment
|
||||
end_message
|
||||
exit_value_helper
|
||||
}
|
||||
main
|
||||
|
|
|
@ -14,16 +14,49 @@ manually_install_the_plugin() {
|
|||
git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin
|
||||
}
|
||||
|
||||
test_plugin_uninstallation() {
|
||||
# TMUX KEY-BINDING TESTS
|
||||
|
||||
test_plugin_uninstallation_via_tmux_key_binding() {
|
||||
set_tmux_conf_helper <<- HERE
|
||||
run-shell "$TPM_DIR/tpm"
|
||||
HERE
|
||||
|
||||
manually_install_the_plugin
|
||||
|
||||
# opens tmux and test it with `expect`
|
||||
"$CURRENT_DIR/expect_successful_clean_plugins" ||
|
||||
fail_helper "Clean fails"
|
||||
fail_helper "[key-binding] clean fails"
|
||||
|
||||
teardown_helper
|
||||
}
|
||||
|
||||
# SCRIPT TESTS
|
||||
|
||||
test_plugin_uninstallation_via_script() {
|
||||
set_tmux_conf_helper <<- HERE
|
||||
run-shell "$TPM_DIR/tpm"
|
||||
HERE
|
||||
|
||||
manually_install_the_plugin
|
||||
|
||||
script_run_helper "$TPM_DIR/bin/clean_plugins" '"tmux-example-plugin" clean success' ||
|
||||
fail_helper "[script] plugin cleaning fails"
|
||||
|
||||
teardown_helper
|
||||
}
|
||||
|
||||
test_unsuccessful_plugin_uninstallation_via_script() {
|
||||
set_tmux_conf_helper <<- HERE
|
||||
run-shell "$TPM_DIR/tpm"
|
||||
HERE
|
||||
|
||||
manually_install_the_plugin
|
||||
chmod 000 "$PLUGINS_DIR/tmux-example-plugin" # disable directory deletion
|
||||
|
||||
local expected_exit_code=1
|
||||
script_run_helper "$TPM_DIR/bin/clean_plugins" '"tmux-example-plugin" clean fail' "$expected_exit_code" ||
|
||||
fail_helper "[script] unsuccessful plugin cleaning doesn't fail"
|
||||
|
||||
chmod 755 "$PLUGINS_DIR/tmux-example-plugin" # enable directory deletion
|
||||
|
||||
teardown_helper
|
||||
}
|
||||
|
|
2
tpm
2
tpm
|
@ -39,7 +39,7 @@ set_tpm_key_bindings() {
|
|||
tmux 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 "$SCRIPTS_DIR/clean_plugins.sh"
|
||||
tmux bind-key "$clean_key" run-shell "$BINDINGS_DIR/clean_plugins"
|
||||
}
|
||||
|
||||
supported_tmux_version_ok() {
|
||||
|
|
Loading…
Reference in a new issue