home-manager: respect NO_COLOR environment variable

This makes Home Manager respect the NO_COLOR environment variable to
disable coloring from output generated by Home Manager.

This initiative can be found more on https://no-color.org/
This commit is contained in:
Teo Ljungberg 2021-03-01 13:22:33 +01:00 committed by Robert Helgesson
parent ddee030dc7
commit 69e2693342
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 15 additions and 3 deletions

View file

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

View file

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

View file

@ -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)

View file

@ -1873,6 +1873,13 @@ in
'accounts.email.accounts.<name>.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/.
'';
}
];
};
}