home-environment: colorize activation output slightly
This commit is contained in:
parent
870d1d484d
commit
3ee505179f
|
@ -252,6 +252,8 @@ in
|
||||||
let
|
let
|
||||||
pattern = "-home-manager-files/";
|
pattern = "-home-manager-files/";
|
||||||
check = pkgs.writeText "check" ''
|
check = pkgs.writeText "check" ''
|
||||||
|
. ${./lib-bash/color-echo.sh}
|
||||||
|
|
||||||
newGenFiles="$1"
|
newGenFiles="$1"
|
||||||
shift
|
shift
|
||||||
for sourcePath in "$@" ; do
|
for sourcePath in "$@" ; do
|
||||||
|
@ -259,13 +261,13 @@ in
|
||||||
targetPath="$HOME/$relativePath"
|
targetPath="$HOME/$relativePath"
|
||||||
if [[ -e "$targetPath" \
|
if [[ -e "$targetPath" \
|
||||||
&& ! "$(readlink -e "$targetPath")" =~ "${pattern}" ]] ; then
|
&& ! "$(readlink -e "$targetPath")" =~ "${pattern}" ]] ; then
|
||||||
echo -e "Existing file '$targetPath' is in the way"
|
errorEcho "Existing file '$targetPath' is in the way"
|
||||||
collision=1
|
collision=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -v collision ]] ; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
@ -356,7 +358,7 @@ in
|
||||||
home.activationPackage =
|
home.activationPackage =
|
||||||
let
|
let
|
||||||
mkCmd = res: ''
|
mkCmd = res: ''
|
||||||
echo Activating ${res.name}
|
noteEcho Activating ${res.name}
|
||||||
${res.data}
|
${res.data}
|
||||||
'';
|
'';
|
||||||
sortedCommands = dagTopoSort cfg.activation;
|
sortedCommands = dagTopoSort cfg.activation;
|
||||||
|
@ -373,7 +375,9 @@ in
|
||||||
set -eu
|
set -eu
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
${builtins.readFile ./activation-init.sh}
|
. ${./lib-bash/color-echo.sh}
|
||||||
|
|
||||||
|
${builtins.readFile ./lib-bash/activation-init.sh}
|
||||||
|
|
||||||
${activationCmds}
|
${activationCmds}
|
||||||
'';
|
'';
|
||||||
|
|
34
modules/lib-bash/color-echo.sh
Normal file
34
modules/lib-bash/color-echo.sh
Normal 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}"
|
||||||
|
}
|
Loading…
Reference in a new issue