1
0
Fork 0
mirror of synced 2024-11-16 14:35:36 -05:00
tpm/scripts/update_plugin.sh
eggbean 9d4a9e7cad Colourise update response to make failure more apparent
It is too easy to miss when an update fails, so this makes the result
much quicker to understand
2023-07-03 05:56:27 +01:00

85 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# this script handles core logic of updating plugins
if command -v tput >/dev/null; then
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
norm=$(tput sgr0)
fi
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR/helpers"
source "$HELPERS_DIR/plugin_functions.sh"
source "$HELPERS_DIR/utility.sh"
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"
fi
# from now on ignore first script argument
shift
pull_changes() {
local plugin="$1"
local plugin_path="$(plugin_path_helper "$plugin")"
cd "$plugin_path" &&
GIT_TERMINAL_PROMPT=0 git pull &&
GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive
}
update() {
local plugin="$1" output
output=$(pull_changes "$plugin" 2>&1)
if (( $? == 0 )); then
echo_ok " \"${yellow}${plugin}${norm}\" ${green}update success${norm}"
echo_ok "$(echo "$output" | sed -e 's/^/ | /')"
else
echo_err " \"${yellow}${plugin}${norm}\" ${red}update fail${norm}"
echo_err "$(echo "$output" | sed -e 's/^/ | /')"
fi
}
update_all() {
echo_ok "Updating all plugins!"
echo_ok ""
local plugins="$(tpm_plugins_list_helper)"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
# updating only installed plugins
if plugin_already_installed "$plugin_name"; then
update "$plugin_name" &
fi
done
wait
}
update_plugins() {
local plugins="$*"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
if plugin_already_installed "$plugin_name"; then
update "$plugin_name" &
else
echo_err "$plugin_name not installed!" &
fi
done
wait
}
main() {
ensure_tpm_path_exists
if [ "$1" == "all" ]; then
update_all
else
update_plugins "$*"
fi
exit_value_helper
}
main "$*"