1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 02:39:48 +01:00

home-environment: colorize activation output slightly

This commit is contained in:
Robert Helgesson 2017-05-14 16:17:38 +02:00
parent 870d1d484d
commit 3ee505179f
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
3 changed files with 42 additions and 4 deletions

View file

@ -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}
'';

View file

@ -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}"
}