2014-08-05 12:45:59 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
source "$CURRENT_DIR/shared_functions.sh"
|
|
|
|
|
2014-08-05 13:02:42 -04:00
|
|
|
empty() {
|
|
|
|
[ -z "$1" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if_all() {
|
|
|
|
[ "$1" == "all" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:17:13 -04:00
|
|
|
update_plugin_git() {
|
|
|
|
local plugin; plugin="$1"
|
|
|
|
local branch; branch=":${1##*:}"
|
|
|
|
local plugin_path; plugin_path=$(shared_plugin_path "$plugin")
|
|
|
|
plugin="${1%$branch}"
|
|
|
|
#update only makes sense when no specific branch/revision is set
|
|
|
|
if [ "${branch}" = ":${1}" ]; then
|
|
|
|
cd "$plugin_path" &&
|
|
|
|
GIT_TERMINAL_PROMPT="0" git pull &&
|
|
|
|
GIT_TERMINAL_PROMPT="0" git submodule update --init --recursive
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
update_plugin_web() {
|
|
|
|
local plugin; plugin="$1"
|
|
|
|
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
|
|
|
|
local plugin_path; plugin_path=$(shared_plugin_path "$plugin")
|
|
|
|
(cd "$plugin_path" && rm -rf "${plugin_name}" &&
|
|
|
|
(wget --no-check-certificate "${plugin}" || curl -k -s -O "${plugin}"))
|
|
|
|
}
|
|
|
|
|
|
|
|
update_plugin_local() {
|
|
|
|
local plugin; plugin="$1"
|
|
|
|
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
|
|
|
|
local plugin_path; plugin_path=$(shared_plugin_path "$plugin")
|
|
|
|
cd "$plugin_path" && rm -rf "${plugin_name}" && cp -r "${plugin}" .
|
2014-08-05 13:02:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
2015-05-27 16:17:13 -04:00
|
|
|
local plugin; plugin="$1"
|
|
|
|
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
|
|
|
|
echo_message "Updating \"$plugin_name\""
|
|
|
|
|
|
|
|
local handler; handler="${1%%:*}:"
|
|
|
|
plugin="${1#$handler}"
|
|
|
|
|
|
|
|
case "${handler}" in
|
|
|
|
''|*/*) case "${1}" in
|
|
|
|
/*|~*|\$*) update_plugin_local "${1}" ;;
|
|
|
|
*) update_plugin_git "${1}" ;;
|
|
|
|
esac ;;
|
|
|
|
gh*|github*|git@github.com*) update_plugin_git "${plugin}" ;;
|
|
|
|
git:) update_plugin_git "${plugin}" ;;
|
|
|
|
file:) update_plugin_local "${plugin#//}" ;;
|
|
|
|
http:|ftp:) update_plugin_web "${1}" ;;
|
|
|
|
https:)
|
|
|
|
case "${1}" in
|
|
|
|
*github.com/*) update_plugin_git "${plugin#//github.com/}";;
|
|
|
|
*) update_plugin_web "${1}";;
|
|
|
|
esac ;;
|
|
|
|
*) set_false ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ "${?}" = "0" ] &&
|
|
|
|
echo_message " \"$plugin_name\" update success" ||
|
|
|
|
echo_message " \"$plugin_name\" update fail"
|
2014-08-05 13:02:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update_all() {
|
2015-05-27 16:17:13 -04:00
|
|
|
local plugins plugin; plugins="$(shared_get_tpm_plugins_list)"
|
2014-08-05 12:45:59 -04:00
|
|
|
for plugin in $plugins; do
|
2015-05-27 16:17:13 -04:00
|
|
|
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
|
2014-08-05 13:02:42 -04:00
|
|
|
# updating only installed plugins
|
|
|
|
if plugin_already_installed "$plugin_name"; then
|
2015-05-27 16:17:13 -04:00
|
|
|
update "$plugin"
|
2014-08-05 12:45:59 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-08-05 13:02:42 -04:00
|
|
|
handle_plugin_update() {
|
2015-05-27 16:17:13 -04:00
|
|
|
local arg; arg="$1"
|
2014-08-05 13:02:42 -04:00
|
|
|
|
|
|
|
if empty "$arg"; then
|
|
|
|
cancel
|
|
|
|
|
|
|
|
elif if_all "$arg"; then
|
|
|
|
echo_message "Updating all plugins!"
|
|
|
|
echo_message ""
|
|
|
|
update_all
|
2014-08-05 12:45:59 -04:00
|
|
|
|
2014-08-05 13:02:42 -04:00
|
|
|
elif plugin_already_installed "$arg"; then
|
|
|
|
update "$arg"
|
|
|
|
|
|
|
|
else
|
|
|
|
display_message "It seems this plugin is not installed: $arg"
|
|
|
|
cancel
|
|
|
|
fi
|
|
|
|
}
|
2014-08-05 12:45:59 -04:00
|
|
|
|
|
|
|
main() {
|
2015-05-27 16:17:13 -04:00
|
|
|
local arg; arg="$1"
|
2014-08-05 12:45:59 -04:00
|
|
|
shared_set_tpm_path_constant
|
2014-08-05 13:02:42 -04:00
|
|
|
handle_plugin_update "$arg"
|
|
|
|
reload_tmux_environment
|
|
|
|
end_message
|
2014-08-05 12:45:59 -04:00
|
|
|
}
|
2014-08-05 13:02:42 -04:00
|
|
|
main "$1"
|