[provisioning] Add color output

This commit is contained in:
Correl Roush 2020-06-20 20:04:46 -04:00
parent 5b458a188a
commit 530f031678

View file

@ -7,6 +7,17 @@ RECIPES=$(ls $RECIPE_PATH|grep -v '^_' | sort)
INSTALL=() INSTALL=()
STACK=() STACK=()
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
dim="$(tput dim)"
normal="$(tput sgr0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
fi
fi
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
-D|--debug) -D|--debug)
@ -70,7 +81,7 @@ function _run {
echo "$msg..." echo "$msg..."
$@ $@
fi fi
echo "done." echo "${green}done.${normal}"
} }
function _recipe { function _recipe {
@ -83,15 +94,17 @@ function _recipe {
recipe="$1" recipe="$1"
path="${RECIPE_PATH}" path="${RECIPE_PATH}"
else else
echo "Could not load recipe '$1'" >&2 echo "${bold}${red}Could not load recipe '$1'${normal}" >&2
exit 1 exit 1
fi fi
STACK+=("$1") STACK+=("$1")
pushd "$path" pushd "$path" >/dev/null
echo "-- Recipe '${STACK[@]}' --" echo "${dim}-- Recipe [${STACK[@]}]'${normal}"
source "./${recipe}" source "./${recipe}"
echo "-- Recipe '${STACK[@]}' --" popd >/dev/null
popd unset 'STACK[-1]'
echo "${dim}-- Recipe [${STACK[@]}]${normal}"
} }
USER=${USER:-$(whoami)} USER=${USER:-$(whoami)}
@ -102,12 +115,11 @@ if [ -z "${INSTALL[@]}" ]; then
fi fi
echo "-- Provisioning [${INSTALL[@]}] --"
for recipe in "${INSTALL[@]}"; do for recipe in "${INSTALL[@]}"; do
_recipe $recipe _recipe $recipe
done done
echo "Finished" echo "${green}Finished${normal}"
if [ -n "$RESTART_SHELL" ]; then if [ -n "$RESTART_SHELL" ]; then
echo "Restarting shell." echo "Restarting shell."
exec $SHELL exec $SHELL