Enable updating plugins via cli executable

This commit is contained in:
Bruno Sutic
2015-08-02 00:41:06 +02:00
parent ce902f906a
commit 7ff8de38a4
8 changed files with 127 additions and 47 deletions

View File

@ -1,39 +1,58 @@
#!/usr/bin/env bash
# this script handles core logic of updating plugins
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/shared_functions.sh"
empty() {
[ -z "$1" ]
TMUX_ECHO_FLAG="$1"
shift
# 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_all() {
[ "$1" == "all" ]
}
if use_tmux_echo; then
# use tmux specific echo-ing
echo_ok() {
echo_message "$*"
}
cancel() {
exit 0
}
echo_err() {
echo_message "$*"
}
else
echo_ok() {
echo "$*"
}
echo_err() {
fail_helper "$*"
}
fi
pull_changes() {
local plugin="$1"
local plugin_path=$(shared_plugin_path "$plugin")
cd $plugin_path &&
local plugin_path="$(shared_plugin_path "$plugin")"
cd "$plugin_path" &&
GIT_TERMINAL_PROMPT=0 git pull &&
GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive
}
update() {
local plugin="$1"
echo_message "Updating \"$plugin\""
echo_ok "Updating \"$plugin\""
$(pull_changes "$plugin" > /dev/null 2>&1) &&
echo_message " \"$plugin\" update success" ||
echo_message " \"$plugin\" update fail"
echo_ok " \"$plugin\" update success" ||
echo_err " \"$plugin\" update fail"
}
update_all() {
echo_ok "Updating all plugins!"
echo_ok ""
local plugins="$(shared_get_tpm_plugins_list)"
for plugin in $plugins; do
local plugin_name="$(shared_plugin_name "$plugin")"
@ -44,31 +63,25 @@ update_all() {
done
}
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
update_plugins() {
local plugins="$*"
for plugin in $plugins; do
local plugin_name="$(shared_plugin_name "$plugin")"
if plugin_already_installed "$plugin_name"; then
update "$plugin_name"
else
echo_err "$plugin_name not installed!"
fi
done
}
main() {
local arg="$1"
shared_set_tpm_path_constant
handle_plugin_update "$arg"
reload_tmux_environment
end_message
if [ "$1" == "all" ]; then
update_all
else
update_plugins "$*"
fi
exit_value_helper
}
main "$1"
main "$*"

View File

@ -1,44 +0,0 @@
#!/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() {
local plugins="$(shared_get_tpm_plugins_list)"
echo_message "Installed plugins:"
echo_message ""
for plugin in $plugins; do
# displaying only installed plugins
if plugin_already_installed "$plugin"; then
local plugin_name="$(shared_plugin_name "$plugin")"
echo_message " $plugin_name"
fi
done
echo_message ""
echo_message "Type plugin name to update it."
echo_message ""
echo_message "- \"all\" - updates all plugins"
echo_message "- ENTER - cancels"
}
update_plugin_prompt() {
tmux command-prompt -p 'plugin update:' " \
send-keys C-c; \
run-shell '$CURRENT_DIR/update_plugin.sh %1'"
}
main() {
reload_tmux_environment
shared_set_tpm_path_constant
display_plugin_update_list
update_plugin_prompt
}
main

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ $# -eq 0]; then
exit 0
fi
source "$CURRENT_DIR/shared_functions.sh"
main() {
"$CURRENT_DIR/update_plugin.sh" --tmux-echo "$*"
reload_tmux_environment
end_message
}
main "$*"