diff --git a/doc/release-notes/rl-2105.adoc b/doc/release-notes/rl-2105.adoc index c68fba51a..cdf470ac5 100644 --- a/doc/release-notes/rl-2105.adoc +++ b/doc/release-notes/rl-2105.adoc @@ -111,6 +111,9 @@ configure.packages.*.start -> programs.neovim.plugins = [ { plugin = ...; }] configure.customRC -> programs.neovim.extraConfig ---- +* Home Manager now respects the `NO_COLOR` environment variable as per +https://no-color.org/[]. + [[sec-release-21.05-state-version-changes]] === State Version Changes diff --git a/home-manager/home-manager b/home-manager/home-manager index fb9f440c4..56caebeb0 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -221,7 +221,7 @@ function doSwitch() { function doListGens() { # Whether to colorize the generations output. local color="never" - if [[ -t 1 ]]; then + if [[ ! -v NO_COLOR && -t 1 ]]; then color="always" fi diff --git a/modules/lib-bash/color-echo.sh b/modules/lib-bash/color-echo.sh index ef708b29c..ac36cedc6 100644 --- a/modules/lib-bash/color-echo.sh +++ b/modules/lib-bash/color-echo.sh @@ -1,5 +1,7 @@ # The check for terminal output and color support is heavily inspired # by https://unix.stackexchange.com/a/10065. +# +# Allow opt out by respecting the `NO_COLOR` environment variable. function setupColors() { normalColor="" @@ -7,8 +9,8 @@ function setupColors() { warnColor="" noteColor="" - # Check if stdout is a terminal. - if [[ -t 1 ]]; then + # Enable colors for terminals, and allow opting out. + if [[ ! -v NO_COLOR && -t 1 ]]; then # See if it supports colors. local ncolors ncolors=$(tput colors) diff --git a/modules/misc/news.nix b/modules/misc/news.nix index c568a939e..301136441 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1873,6 +1873,13 @@ in 'accounts.email.accounts..msmtp.enable' is true. ''; } + { + time = "2021-03-03T22:16:05+00:00"; + message = '' + Home Manager now respects the 'NO_COLOR' environment variable as per + https://no-color.org/. + ''; + } ]; }; }