mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 03:29:45 +01:00
home-environment: colorize activation output slightly
This commit is contained in:
parent
870d1d484d
commit
3ee505179f
3 changed files with 42 additions and 4 deletions
|
@ -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}
|
||||
'';
|
||||
|
|
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