2014-08-05 12:45:59 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2015-08-01 18:41:06 -04:00
|
|
|
# this script handles core logic of updating plugins
|
|
|
|
|
2014-08-05 12:45:59 -04:00
|
|
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
source "$CURRENT_DIR/shared_functions.sh"
|
|
|
|
|
2015-08-01 18:41:06 -04:00
|
|
|
TMUX_ECHO_FLAG="$1"
|
|
|
|
shift
|
2014-08-05 13:02:42 -04:00
|
|
|
|
2015-08-01 18:41:06 -04:00
|
|
|
# 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" ]
|
2014-08-05 13:02:42 -04:00
|
|
|
}
|
|
|
|
|
2015-08-01 18:41:06 -04:00
|
|
|
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
|
2014-08-05 13:02:42 -04:00
|
|
|
|
|
|
|
pull_changes() {
|
|
|
|
local plugin="$1"
|
2015-08-01 18:41:06 -04:00
|
|
|
local plugin_path="$(shared_plugin_path "$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"
|
2015-08-01 18:41:06 -04:00
|
|
|
echo_ok "Updating \"$plugin\""
|
2014-08-05 13:02:42 -04:00
|
|
|
$(pull_changes "$plugin" > /dev/null 2>&1) &&
|
2015-08-01 18:41:06 -04:00
|
|
|
echo_ok " \"$plugin\" update success" ||
|
|
|
|
echo_err " \"$plugin\" update fail"
|
2014-08-05 13:02:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
update_all() {
|
2015-08-01 18:41:06 -04:00
|
|
|
echo_ok "Updating all plugins!"
|
|
|
|
echo_ok ""
|
2014-08-05 12:45:59 -04:00
|
|
|
local plugins="$(shared_get_tpm_plugins_list)"
|
|
|
|
for plugin in $plugins; do
|
2014-08-05 13:02:42 -04:00
|
|
|
local plugin_name="$(shared_plugin_name "$plugin")"
|
|
|
|
# updating only installed plugins
|
|
|
|
if plugin_already_installed "$plugin_name"; then
|
|
|
|
update "$plugin_name"
|
2014-08-05 12:45:59 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-08-01 18:41:06 -04:00
|
|
|
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
|
2014-08-05 13:02:42 -04:00
|
|
|
}
|
2014-08-05 12:45:59 -04:00
|
|
|
|
|
|
|
main() {
|
|
|
|
shared_set_tpm_path_constant
|
2015-08-01 18:41:06 -04:00
|
|
|
if [ "$1" == "all" ]; then
|
|
|
|
update_all
|
|
|
|
else
|
|
|
|
update_plugins "$*"
|
|
|
|
fi
|
|
|
|
exit_value_helper
|
2014-08-05 12:45:59 -04:00
|
|
|
}
|
2015-08-01 18:41:06 -04:00
|
|
|
main "$*"
|