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