From 4ca6dd9a366f1256e522fc067ad42bb57fb788de Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 19 Jun 2020 17:56:09 +0300 Subject: [PATCH] helpers: Add --slient option to bash-it update --- lib/helpers.bash | 66 ++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index e7265489..2cb0b18c 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -159,14 +159,29 @@ _bash-it_update-dev() { _about 'updates Bash-it to the latest master' _group 'lib' - _bash-it_update- dev + _bash-it_update- dev "$@" } _bash-it_update-stable() { _about 'updates Bash-it to the latest tag' _group 'lib' - _bash-it_update- stable + _bash-it_update- stable "$@" +} + +_bash-it_pull_and_update_inner() { + git checkout "$1" &> /dev/null + if [[ $? -eq 0 ]]; then + echo "Bash-it successfully updated." + echo "" + echo "Migrating your installation to the latest $2 version now..." + _bash-it-migrate + echo "" + echo "All done, enjoy!" + bash-it reload + else + echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." + fi } _bash-it_update-() { @@ -174,6 +189,12 @@ _bash-it_update-() { _param '1: What kind of update to do (stable|dev)' _group 'lib' + declare silent + for word in $@; do + if [[ ${word} == "--silent" || ${word} == "-s" ]]; then + silent=true + fi + done local old_pwd="${PWD}" cd "${BASH_IT}" || return @@ -215,29 +236,24 @@ _bash-it_update-() { git log --format="%h: $description (%an)" -1 $i done echo "" - read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP - case $RESP in - [yY]|"") - git checkout "${TARGET}" &> /dev/null - if [[ $? -eq 0 ]]; then - echo "Bash-it successfully updated." - echo "" - echo "Migrating your installation to the latest $version version now..." - _bash-it-migrate - echo "" - echo "All done, enjoy!" - bash-it reload - else - echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." - fi - ;; - [nN]) - echo "Not upgrading…" - ;; - *) - echo -e "\033[91mPlease choose y or n.\033[m" - ;; - esac + + if [[ $silent ]]; then + echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." + _bash-it_pull_and_update_inner $TARGET $version + else + read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP + case $RESP in + [yY]|"") + _bash-it_pull_and_update_inner $TARGET $version + ;; + [nN]) + echo "Not upgrading…" + ;; + *) + echo -e "\033[91mPlease choose y or n.\033[m" + ;; + esac + fi else if [[ ${version} == "stable" ]]; then echo "You're on the latest stable version. If you want to check out the latest 'dev' version, please run \"bash-it update dev\""