ip: Add color output option
Subsystems (2)
PATCH 1/1 ip: Add color output option
It is hard to quickly find what you are looking for in the output of the ip command. Color helps.
This patch adds a '-c' flag to highlight these with individual colors:
- interface name
- ip addresse
- mac addresse
- up/down state
--- include/color.h | 17 ++++++++++++++++ ip/Makefile | 2 +- ip/color.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ip/ip.c | 5 ++++- ip/ipaddress.c | 43 +++++++++++++++++++++++++++++---------- man/man8/ip.8 | 7 ++++++- 6 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 include/color.h create mode 100644 ip/color.c
include/color.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __COLOR_H__ +#define __COLOR_H__ 1 + +enum color_attr +{ +COLOR_IFNAME , +COLOR_MAC , +COLOR_INET , +COLOR_INET6 , +COLOR_OPERSTATE_UP , +COLOR_OPERSTATE_DOWN +}; + +void enable_color (void ); +int color_fprintf (FILE *fp,enum color_attr attr,const char *fmt, ...); + +#endif
ip/Makefile +1 -1
@@ -6,7 +6,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o link_vti6.o \ iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \ link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o \ - iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o + iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o color.o RTMONOBJ=rtmon.o
ip/color.c new file +63 -0
63 lines not on this page · raw message
ip/ip.c +4 -1
@@ -23,6 +23,7 @@#include "utils.h" #include "ip_common.h" #include "namespace.h" +#include "color.h" int preferred_family =AF_UNSPEC ;int human_readable =0 ;
@@ -56,7 +57,7 @@ static void usage(void)" -4 | -6 | -I | -D | -B | -0 |\n" " -l[oops] { maximum-addr-flush-attempts } |\n" " -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n" -" -rc[vbuf] [size] | -n[etns] name | -a[ll] }\n"); +" -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}\n");exit (-1 ); }
@@ -257,6 +258,8 @@ int main(int argc, char **argv)exit (-1 ); } rcvbuf = size; + }else if (matches (opt,"-color" ) ==0 ) { +enable_color (); }else if (matches (opt,"-help" ) ==0 ) {usage (); }else if (matches (opt,"-netns" ) ==0 ) {
ip/ipaddress.c +32 -11
73 lines not on this page · raw message
man/man8/ip.8 +6 -1
@@ -33,7 +33,8 @@ ip \- show / manipulate routing, devices, policy routing and tunnels .BR inet " | " inet6 " | " ipx " | " dnet " | " link " } | " \fB\-o\fR[\fIneline\fR] | \fB\-n\fR[\fIetns\fR] name | -\fB\-a\fR[\fIll\fR] } +\fB\-a\fR[\fIll\fR] | +\fB\-c\fR[\fIolor\fR] } .SH OPTIONS
@@ -165,6 +166,10 @@ to .BR "\-a" , " \-all" executes specified command over all objects, it depends if command supports this option. +.TP +.BR "\-c" , " -color" +Use color output. + .SH IP - COMMAND SYNTAX .SS
Signature · 1 line
2.3.5
Quoted 8 lines · Mathias Nyman
It is hard to quickly find what you are looking for in the output of the ip command. Color helps.
This patch adds a '-c' flag to highlight these with individual colors:
- interface name
- ip addresse
- mac addresse
- up/down state
idea looks good, but the patch doesn't apply at all, since it's whitespace damaged. Also there is no SOB.
Quoted 4 lines · Alexei Starovoitov
Quoted 3 lines · Mathias Nyman
It is hard to quickly find what you are looking for in the output of the ip command. Color helps.
Quoted 8 lines
Quoted 5 lines
This patch adds a '-c' flag to highlight these with individual colors:
- interface name
- ip addresse
- mac addresse
- up/down stateidea looks good, but the patch doesn't apply at all, since it's whitespace damaged. Also there is no SOB.
You also might want to move the library bits into lib/ so that not only ip but also other tools could use it in future. So -c is neither taken in ip nor in tc or ss, that's good. ;)
Quoted 5 lines · Daniel Borkmann
Quoted 4 lines · Alexei Starovoitov
Quoted 3 lines · Mathias Nyman
It is hard to quickly find what you are looking for in the output of the ip command. Color helps.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
This patch adds a '-c' flag to highlight these with individual colors:
- interface name
- ip addresse
- mac addresse
- up/down stateidea looks good, but the patch doesn't apply at all, since it's whitespace damaged. Also there is no SOB.
First timer; the v2 should fix these.
Quoted 4 lines
You also might want to move the library bits into
lib/so that not only ip but also other tools could use it in future. So -c is neither taken in ip nor in tc or ss, that's good. ;)
I don't understand what you mean by "-c is neither taken in ip nor in tc or ss". I am not finding a common place where to handle the -color flag for ip, tc and ss, if that's what you mean. The common color.c is under lib/ in v2 though.
Thanks for super fast feedback guys!
On 04/18/2015 12:22 PM, Mathias Nyman wrote:
...
Quoted 2 lines
I don't understand what you mean by "-c is neither taken in ip nor in tc or ss".
That just means we could in future consider to consistently add support for -c flag in those tools, too.