Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling for installer script #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions bin/installer
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -o pipefail

CONFIG_DIR="$HOME/.hammerspoon"
SPOONS_DIR="$CONFIG_DIR/Spoons"

Expand Down Expand Up @@ -32,6 +34,11 @@ saysuccess() {
dotsay "✅ @blue[[$1]]"
}

sayerror() {
printf " "
dotsay "❌ @red[[$1]]"
}

sayinfo() {
printf " "
dotsay "+ @yellow[[$1]]"
Expand All @@ -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' \
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down