1
0
Fork 0
mirror of synced 2024-06-02 07:11:11 -04:00
tpm/scripts/update_plugin.sh

78 lines
1.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# this script handles core logic of updating plugins
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2015-08-03 09:12:45 -04:00
HELPERS_DIR="$CURRENT_DIR/helpers"
2015-08-03 11:40:50 -04:00
source "$HELPERS_DIR/plugin_functions.sh"
source "$HELPERS_DIR/utility.sh"
if [[ "$1" == "--tmux-echo" ]]; then # tmux-specific echo functions
2015-08-03 09:12:45 -04:00
source "$HELPERS_DIR/tmux_echo_functions.sh"
else # shell output functions
source "$HELPERS_DIR/shell_echo_functions.sh"
fi
2014-08-05 13:02:42 -04:00
2015-08-03 09:12:45 -04:00
# from now on ignore first script argument
shift
2014-08-05 13:02:42 -04:00
pull_changes() {
local plugin="$1"
2015-08-03 11:40:50 -04:00
local plugin_path="$(plugin_path_helper "$plugin")"
cd "$plugin_path" &&
2015-02-08 09:38:55 -05:00
GIT_TERMINAL_PROMPT=0 git pull &&
GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive
2014-08-05 13:02:42 -04:00
}
update() {
local plugin="$1"
echo_ok "Updating \"$plugin\""
2014-08-05 13:02:42 -04:00
$(pull_changes "$plugin" > /dev/null 2>&1) &&
echo_ok " \"$plugin\" update success" ||
echo_err " \"$plugin\" update fail"
2014-08-05 13:02:42 -04:00
}
update_all() {
echo_ok "Updating all plugins!"
echo_ok ""
2015-08-03 11:40:50 -04:00
local plugins="$(tpm_plugins_list_helper)"
for plugin in $plugins; do
run_parallel_all() {
local plugin_name="$(plugin_name_helper "$plugin")"
# updating only installed plugins
if plugin_already_installed "$plugin_name"; then
update "$plugin_name"
fi
}
run_parallel_all &
done
wait
}
update_plugins() {
local plugins="$*"
for plugin in $plugins; do
run_parallel() {
local plugin_name="$(plugin_name_helper "$plugin")"
if plugin_already_installed "$plugin_name"; then
update "$plugin_name"
else
echo_err "$plugin_name not installed!"
fi
}
run_parallel &
done
wait
2014-08-05 13:02:42 -04:00
}
main() {
if [[ "$1" == "all" ]]; then
update_all
else
update_plugins "$*"
fi
exit_value_helper
}
main "$*"