From 281600e769a59bad476fc7b25b893204b8d5dc62 Mon Sep 17 00:00:00 2001 From: levabala Date: Thu, 30 Mar 2023 00:41:07 +0200 Subject: [PATCH] feat(installer): add error handling --- bin/installer | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/installer b/bin/installer index c7f4f26..d8538b8 100755 --- a/bin/installer +++ b/bin/installer @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -o pipefail + CONFIG_DIR="$HOME/.hammerspoon" SPOONS_DIR="$CONFIG_DIR/Spoons" @@ -32,6 +34,11 @@ saysuccess() { dotsay "✅ @blue[[$1]]" } +sayerror() { + printf " " + dotsay "❌ @red[[$1]]" +} + sayinfo() { printf " " dotsay "+ @yellow[[$1]]" @@ -41,6 +48,11 @@ indent() { sed 's/^/ /' } +panic() { + sayerror "Error occurred. Please check the previous output" + exit 1 +} + _colorized() { echo "$@" | sed -E \ -e 's/((@(red|green|yellow|blue|magenta|cyan|white|reset|b|u))+)[[]{2}(.*)[]]{2}/\1\4@reset/g' \ @@ -129,8 +141,8 @@ function bootstrap_spoon_install() { if [ ! -d "$SPOONS_DIR/SpoonInstall.spoon" ]; then sayinfo "Installing SpoonInstall.spoon in $SPOONS_DIR" - wget -nv $url -O $destination | indent - unzip -d $SPOONS_DIR $destination | indent + wget -nv $url -O $destination | indent || panic + unzip -d $SPOONS_DIR $destination | indent || panic else saysuccess "SpoonInstall.spoon already setup" fi @@ -145,7 +157,7 @@ function bootstrap_vim_mode_spoon() { sayinfo "Cloning VimMode.spoon from Git" echo - git clone https://github.com/dbalatero/VimMode.spoon "$dir" | indent + git clone https://github.com/dbalatero/VimMode.spoon "$dir" | indent || panic echo fi