diff --git a/modules/home-environment.nix b/modules/home-environment.nix index e58f9324..694a2aa0 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -252,6 +252,8 @@ in let pattern = "-home-manager-files/"; check = pkgs.writeText "check" '' + . ${./lib-bash/color-echo.sh} + newGenFiles="$1" shift for sourcePath in "$@" ; do @@ -259,13 +261,13 @@ in targetPath="$HOME/$relativePath" if [[ -e "$targetPath" \ && ! "$(readlink -e "$targetPath")" =~ "${pattern}" ]] ; then - echo -e "Existing file '$targetPath' is in the way" + errorEcho "Existing file '$targetPath' is in the way" collision=1 fi done if [[ -v collision ]] ; then - echo -e "Please move the above files and try again" + errorEcho "Please move the above files and try again" exit 1 fi ''; @@ -356,7 +358,7 @@ in home.activationPackage = let mkCmd = res: '' - echo Activating ${res.name} + noteEcho Activating ${res.name} ${res.data} ''; sortedCommands = dagTopoSort cfg.activation; @@ -373,7 +375,9 @@ in set -eu set -o pipefail - ${builtins.readFile ./activation-init.sh} + . ${./lib-bash/color-echo.sh} + + ${builtins.readFile ./lib-bash/activation-init.sh} ${activationCmds} ''; diff --git a/modules/activation-init.sh b/modules/lib-bash/activation-init.sh similarity index 100% rename from modules/activation-init.sh rename to modules/lib-bash/activation-init.sh diff --git a/modules/lib-bash/color-echo.sh b/modules/lib-bash/color-echo.sh new file mode 100644 index 00000000..e357bf70 --- /dev/null +++ b/modules/lib-bash/color-echo.sh @@ -0,0 +1,34 @@ +function setupColors() { + normalColor="" + errorColor="" + warnColor="" + noteColor="" + + # Check if stdout is a terminal. + if [[ -t 1 ]]; then + # See if it supports colors. + local ncolors + ncolors=$(tput colors) + + if [[ -n "$ncolors" && "$ncolors" -ge 8 ]]; then + normalColor="$(tput sgr0)" + errorColor="$(tput bold)$(tput setaf 1)" + warnColor="$(tput setaf 3)" + noteColor="$(tput bold)$(tput setaf 6)" + fi + fi +} + +setupColors + +function errorEcho() { + echo "${errorColor}$*${normalColor}" +} + +function warnEcho() { + echo "${warnColor}$*${normalColor}" +} + +function noteEcho() { + echo "${noteColor}$*${normalColor}" +}