From patchwork Wed Mar 19 21:51:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 14023209 X-Patchwork-Delegate: dsahern@gmail.com Received: from maynard.decadent.org.uk (maynard.decadent.org.uk [65.21.191.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF0A0219E8C for ; Wed, 19 Mar 2025 21:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.21.191.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742421122; cv=none; b=pXbwnGO+s3z4RV0+/g0oqfdQN5/OH6u05CZoM0ENrl2+SKa3DyxIcsWtoUg+xvCUepLJbCGgx64ugkmaVNtQLGXUGm7OSnndkuPpO69qaLbDUsLMD468kDOpuk4lClAiSFvv5yMUDrFh6rdmdXUxfDntHm+c3rc48Dtbe3dsDY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742421122; c=relaxed/simple; bh=fovONEDMtM7seNcbOra/8SfscccH4qtd4sJJZ0rt9Ho=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Gt6I8cZscgXIDqm3z7FsDhhRyZVU4TxRm9CUrAxBu4VY+qKje6eoT89Oxag2NpBBzI1JRQH5ygGt34R85jIXxVoYEFj03TQaH8J0aeZk74oaNbeJakmXw1uVM8u4qlzRn3nVQWFT8v1oop77R7B0bKcHOoXbqcF+HzoWA4eahzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=decadent.org.uk; arc=none smtp.client-ip=65.21.191.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=decadent.org.uk Received: from [2a02:578:851f:1502:391e:c5f5:10e2:b9a3] (helo=deadeye) by maynard with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tv1KQ-009oev-2Z; Wed, 19 Mar 2025 21:51:58 +0000 Received: from ben by deadeye with local (Exim 4.98) (envelope-from ) id 1tv1KP-00000002bLb-2qAw; Wed, 19 Mar 2025 22:51:57 +0100 Date: Wed, 19 Mar 2025 22:51:57 +0100 From: Ben Hutchings To: netdev@vger.kernel.org Cc: 1088739@bugs.debian.org Subject: [PATCH iproute2 2/2] color: Handle NO_COLOR environment variable in default_color_opt() Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a02:578:851f:1502:391e:c5f5:10e2:b9a3 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on maynard); SAEximRunCond expanded to false X-Patchwork-Delegate: dsahern@gmail.com The NO_COLOR environment variable is a widely supported way for users to disable coloured text output. See . In case iproute2 is configured to use colours by default, allow this to be overridden by setting NO_COLOR. This is done in default_color_opt() so that colours can still be explicitly enabled with a command-line option. Signed-off-by: Ben Hutchings --- lib/color.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/color.c b/lib/color.c index 5c4cc329..3c6db08d 100644 --- a/lib/color.c +++ b/lib/color.c @@ -83,6 +83,13 @@ static void enable_color(void) int default_color_opt(void) { + const char *no_color; + + /* If NO_COLOR has a non-empty value, coloured output is never wanted */ + no_color = getenv("NO_COLOR"); + if (no_color && *no_color) + return COLOR_OPT_NEVER; + return CONF_COLOR; }