mirror of
https://github.com/tmux-plugins/tpm.git
synced 2025-09-06 01:36:59 +00:00
update_plugin script
This commit is contained in:
@ -1,34 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# when invoked with `prefix + U` this script:
|
||||
# - shows a list of installed plugins
|
||||
# - starts a prompt to enter the name of the plugin that will be updated
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/shared_functions.sh"
|
||||
|
||||
display_plugin_update_list() {
|
||||
empty() {
|
||||
[ -z "$1" ]
|
||||
}
|
||||
|
||||
if_all() {
|
||||
[ "$1" == "all" ]
|
||||
}
|
||||
|
||||
cancel() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
pull_changes() {
|
||||
local plugin="$1"
|
||||
local plugin_path=$(shared_plugin_path "$plugin")
|
||||
cd $plugin_path &&
|
||||
git pull &&
|
||||
git submodule update --init --recursive
|
||||
}
|
||||
|
||||
update() {
|
||||
local plugin="$1"
|
||||
echo_message "Updating \"$plugin\""
|
||||
$(pull_changes "$plugin" > /dev/null 2>&1) &&
|
||||
echo_message " \"$plugin\" update success" ||
|
||||
echo_message " \"$plugin\" update fail"
|
||||
}
|
||||
|
||||
|
||||
update_all() {
|
||||
local plugins="$(shared_get_tpm_plugins_list)"
|
||||
for plugin in $plugins; do
|
||||
# displaying only installed plugins
|
||||
if plugin_already_cloned "$plugin"; then
|
||||
echo_message "$plugin"
|
||||
local plugin_name="$(shared_plugin_name "$plugin")"
|
||||
# updating only installed plugins
|
||||
if plugin_already_installed "$plugin_name"; then
|
||||
update "$plugin_name"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
update_plugin_prompt() {
|
||||
tmux command-prompt -p 'plugin update:' " \
|
||||
send-keys C-m; \
|
||||
run-shell '$CURRENT_DIR/update_plugin.sh %1'"
|
||||
}
|
||||
handle_plugin_update() {
|
||||
local arg="$1"
|
||||
|
||||
if empty "$arg"; then
|
||||
cancel
|
||||
|
||||
elif if_all "$arg"; then
|
||||
echo_message "Updating all plugins!"
|
||||
echo_message ""
|
||||
update_all
|
||||
|
||||
elif plugin_already_installed "$arg"; then
|
||||
update "$arg"
|
||||
|
||||
else
|
||||
display_message "It seems this plugin is not installed: $arg"
|
||||
cancel
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
reload_tmux_environment
|
||||
local arg="$1"
|
||||
shared_set_tpm_path_constant
|
||||
display_plugin_update_list
|
||||
update_plugin_prompt
|
||||
handle_plugin_update "$arg"
|
||||
reload_tmux_environment
|
||||
end_message
|
||||
}
|
||||
main
|
||||
main "$1"
|
||||
|
Reference in New Issue
Block a user