#9 Enable colorful command output in interactive shells
Closed 3 months ago by norbertus. Opened 8 months ago by samfoxman.
https://github.com/XMB5/iproute-rpm rawhide  into  rawhide

Enable colorful command output in interactive shells
Sam Foxman • 8 months ago  
colorip.csh
file added
+5
@@ -0,0 +1,5 @@

+ # skip everything for non-interactive shells

+ if (! $?prompt) exit

+ 

+ alias ip 'ip -color=auto'

+ alias bridge 'bridge -color=auto'

colorip.sh
file added
+7
@@ -0,0 +1,7 @@

+ # color-ip initialization

+ 

+ # Skip all for noninteractive shells.

+ [ ! -t 0 ] && return

According to ip man page for "color" option, "If parameter is auto, stdout is checked to be a terminal before enabling color output.", so you shouldn't need this check before the alias.

+ 

+ alias ip='ip -color=auto'

+ alias bridge='bridge -color=auto'

colortc.csh
file added
+4
@@ -0,0 +1,4 @@

+ # skip everything for non-interactive shells

+ if (! $?prompt) exit

+ 

+ alias tc 'tc -color=auto'

colortc.sh
file added
+6
@@ -0,0 +1,6 @@

+ # color-tc initialization

+ 

+ # Skip all for noninteractive shells.

+ [ ! -t 0 ] && return

+ 

+ alias tc='tc -color=auto'

iproute.spec
file modified
+14
@@ -7,6 +7,10 @@

  %endif

  URL:                https://kernel.org/pub/linux/utils/net/%{name}2/

  Source0:            https://kernel.org/pub/linux/utils/net/%{name}2/%{name}2-%{version}.tar.xz

+ Source100:          colorip.sh

+ Source101:          colorip.csh

+ Source102:          colortc.sh

+ Source103:          colortc.csh

  

  

  License:            GPL-2.0-or-later AND NIST-PD
@@ -86,6 +90,14 @@

  %install

  %make_install

  

+ # ip command colorization

+ %global profiledir %{_sysconfdir}/profile.d

+ mkdir -p %{buildroot}%{profiledir}

+ install -p -m 644 %{SOURCE100} %{buildroot}%{profiledir}

+ install -p -m 644 %{SOURCE101} %{buildroot}%{profiledir}

+ install -p -m 644 %{SOURCE102} %{buildroot}%{profiledir}

+ install -p -m 644 %{SOURCE103} %{buildroot}%{profiledir}

+ 

  echo '.so man8/tc-cbq.8' > %{buildroot}%{_mandir}/man8/cbq.8

  

  # libnetlink
@@ -114,6 +126,7 @@

  %exclude %{_sbindir}/tc

  %exclude %{_sbindir}/routel

  %{_datadir}/bash-completion/completions/devlink

+ %{profiledir}/colorip.*

  

  %files tc

  %license COPYING
@@ -124,6 +137,7 @@

  %{_libdir}/tc/*

  %{_sbindir}/tc

  %{_datadir}/bash-completion/completions/tc

+ %{profiledir}/colortc.*

  

  %if ! 0%{?_module_build}

  %files doc

no initial comment

The ip, bridge, and tc commands can produce colorful output (Try ip -color=auto addr in your terminal).
This patch adds shell aliases to enable color by default in interactive shells.

I contacted the iproute2 developers, and they agree that color should be enabled by default, and should be set by distros.

According to ip man page for "color" option, "If parameter is auto, stdout is checked to be a terminal before enabling color output.", so you shouldn't need this check before the alias.

Hi Sam, thanks for you contribution!

I think I can give a try to a slightly different upstream solution to avoid providing additional files for shell aliases. Let's see if upstream maintainers are keen to take this alternative approach in consideration.

If this doesn't work, I'll merge this PR provided the above comment is addressed for all shell alias files.

Closing as fixed in iproute-6.7.0-1.fc40 with a different approach on configure script. Thanks for your contribution!

Pull-Request has been closed by norbertus

3 months ago