Skip to content

Instantly share code, notes, and snippets.

@Linux-BSD

Linux-BSD/001-README.md

Last active May 3, 2021
Embed
What would you like to do?
Colorizing outputs of some FreeBSD CLI programs

Colorized outputs for some FreeBSD CLI programs

More schreenshots uploaded here.

Screen shot

Commands Colorized so far...

  • zpool
  • zfs
  • geom
  • gpart
  • geli
  • pfctl
  • sockstat
  • pciconf
  • usbconfig
  • vnstat

The idea is faily simple - Install grc using pkg-ng (pkg install grc) and create conf files for various FreeBSD CLI utilities.

Put the attached files under /usr/local/share/grc directory, and then modify /usr/local/etc/grc.conf as shown below. After that running these commands prefixed with grc will give you colorized output. e.g. grc pfctl -s rules.

NOTE: I've selected the colors and segments I want to highlight based on my tastes. Feel free to modify as per your tastes.


# Put these at the end of /usr/local/etc/grc.conf 
# -----------------------------------------------------------------
# # pciconf
(^|[/\w\.]+/)pciconf\s?
conf.pciconf

# # usbconfig
(^|[/\w\.]+/)usbconfig\s?
conf.usbconfig

# # usbconfig
(^|[/\w\.]+/)sockstat\s?
conf.sockstat

# # vnstat
(^|[/\w\.]+/)vnstat\s?
conf.vnstat

# # geli
(^|[/\w\.]+/)geli\s?
conf.geli

# # geom
(^|[/\w\.]+/)geom\s?
conf.geom

# # gpart
(^|[/\w\.]+/)gpart\s?
conf.gpart

# # pfctl
(^|[/\w\.]+/)pfctl\s?
conf.pfctl

# # zpool
(^|[/\w\.]+/)zpool\s?
conf.zpool

# # zfs
(^|[/\w\.]+/)zfs\s?
conf.zfs
regexp=^(ugen)(\d+)\.(\d+):\s+<([^>]+)>\s+at\s+usbus(\d+).*
colors="\033[38;5;241m","\033[38;5;241m",bright_yellow,bright_cyan,"\033[38;5;213m",bright_yellow
#regexp=^(ugen)(\d+)\.(\d+):\s+<([^>]+)>\s+at\s+usbus(\d+).*spd=(\w+)\s+\(([^\)]+)\)\s+pwr=(\w+)\s+\(([^\)]+)\)
#colors="\033[38;5;241m","\033[38;5;241m",bright_yellow,bright_cyan,bright_green,bright_yellow,bright_blue,bright_magenta,bright_green,bright_cyan
======
regexp=spd=(FULL) \((12Mbps)\)
colors="\033[38;5;241m","\033[38;5;160m","\033[38;5;160m"
======
regexp=spd=(HIGH) \((480Mbps)\)
colors="\033[38;5;241m","\033[38;5;222m","\033[38;5;222m"
======
regexp=spd=(SUPER) \((5.0Gbps)\)
colors="\033[38;5;241m","\033[38;5;112m","\033[38;5;112m"
======
regexp=pwr=(SAVE)\s+\((\d+mA)\)
colors="\033[38;5;241m",white,white
======
regexp=pwr=(ON)\s+\((\d+mA)\)
colors="\033[38;5;241m",bright_red,bright_red
======
regexp=<([^>]+H(?:UB|ub))>
colors="\033[38;5;241m","\033[38;5;247m",
# Disk and Partition
regexp=((?:nvd|ada|da)\d+)(p\d+)?(.eli)?
colors=default,bright_cyan,bright_yellow,"\033[38;5;242m"
======
# ACTIVE
regexp=(ACTIVE)
colors=default,bright_green
======
# Disk and Partition
regexp=(\w+\d+)(p\d+)$
colors=default,bright_cyan,bright_yellow
======
# Header
regexp=(\w+):
colors=default,"\033[38;5;242m"
======
# Header
regexp=(Name|Status|Components|State|EncryptionAlgorithm|KeyLength|Crypto|Flags|Mediasize)
colors=default,bright_white
======
# Providers | Consumers
regexp=(Geom name):
colors=default,bright_blue
======
# Providers | Consumers
regexp=(Providers|Consumers):
colors=default,bright_magenta
======
# Size
regexp=\((\d+(?:\.\d+)?G)\)
colors=default,"\033[38;5;214m"
======
# Size
regexp=\((\d+(?:\.\d+)?M)\)
colors=default,"\033[38;5;221m"
======
# Size
regexp=\((\d+(?:\.\d+)?K)\)
colors=default,"\033[38;5;223m"
======
# Disk and Partition
regexp=((?:nvd|ada|da)\d+)(p\d+)?(.eli)?
colors=default,bright_cyan,bright_yellow,"\033[38;5;242m"
======
# ACTIVE
regexp=(ACTIVE|OK)
colors=unchanged,bright_green
======
# CORRUPT
regexp=(CORRUPT)
colors=unchanged,"\033[41m"
======
# Disk and Partition
regexp=(\w+\d+)(p\d+)$
colors=default,bright_cyan,bright_yellow
======
# Header
regexp=(\w+):
colors=default,"\033[38;5;242m"
======
# Header
regexp=(Name|Status|Components|State|EncryptionAlgorithm|KeyLength|Crypto|Flags|Mediasize|label|type)
colors=default,bright_white
======
# Providers | Consumers
regexp=(Geom name):
colors=default,bright_blue
======
# Providers | Consumers
regexp=(Providers|Consumers):
colors=default,bright_magenta
======
# Size
regexp=\((\d+(?:\.\d+)?G)\)
colors=default,"\033[38;5;214m"
======
# Size
regexp=\((\d+(?:\.\d+)?M)\)
colors=default,"\033[38;5;221m"
======
# Size
regexp=\((\d+(?:\.\d+)?K)\)
colors=default,"\033[38;5;223m"
======
regexp=(GPT|gpt)
colors=default,bright_green
======
regexp=(efi)
colors=default,bright_blue
======
regexp=(freebsd)-(?:(boot)|(swap)|(zfs)|(ufs))
colors=default,bright_cyan,bright_white,"\033[38;5;62m",bright_magenta,bright_green
======
regexp=(linux)-(?:(data|swap))
colors=default,yellow,green,red
======
# Disk and Partition
regexp=((?:nvd|ada|da)\d+)(p\d+)?(.eli)?
colors=default,bright_cyan,bright_yellow,"\033[38;5;242m"
======
# ACTIVE
regexp=(ACTIVE|OK)
colors=unchanged,bright_green
======
# CORRUPT
regexp=(CORRUPT)
colors=unchanged,"\033[41m"
======
# Disk and Partition
regexp=(\w+\d+)(p\d+)$
colors=default,bright_cyan,bright_yellow
======
# Header
regexp=(\w+):
colors=default,"\033[38;5;242m"
======
# Header
regexp=(Name|Status|Components|State|EncryptionAlgorithm|KeyLength|Crypto|Flags|Mediasize|label|type)
colors=default,bright_white
======
# Providers | Consumers
regexp=(Geom name):
colors=default,bright_blue
======
# Providers | Consumers
regexp=(Providers|Consumers):
colors=default,bright_magenta
======
# Size
regexp=\((\d+(?:\.\d+)?G)\)
colors=default,"\033[38;5;214m"
======
# Size
regexp=\((\d+(?:\.\d+)?M)\)
colors=default,"\033[38;5;221m"
======
# Size
regexp=\((\d+(?:\.\d+)?K)\)
colors=default,"\033[38;5;223m"
======
regexp=(GPT|gpt)
colors=default,bright_green
======
regexp=(efi)
colors=default,bright_blue
======
regexp=(freebsd)-(?:(boot)|(swap)|(zfs)|(ufs))
colors=default,bright_cyan,bright_white,"\033[38;5;62m",bright_magenta,bright_green
======
regexp=(linux)-(?:(data|swap))
colors=default,yellow,green,red
======
regexp=^(none\d+)(@pci)
colors=default,"\033[41m","\033[38;5;241m"
======
regexp=^(?:(?!none))(\w+)(@pci)
colors=default,bright_green,"\033[38;5;241m"
======
regexp=(?<=@pci)(\d+):(\d+):(\d+):(\d+)
colors=default,bright_yellow,bright_cyan,bright_magenta,bright_blue
======
regexp=:
colors="\033[38;5;241m"
======
regexp=(\w+)(=0x)(\w+)
colors=default,"\033[38;5;242m","\033[38;5;240m",bright_white
======
regexp=(\w+)\s+(=)\s+'([^\']+)'
colors=default,underline,"\033[38;5;242m",bright_yellow
======
regexp=((?:sub)?class)\s+(=)\s+([^\']+)
colors=default,underline,"\033[38;5;242m",cyan
# IPv4
regexp=\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,33})(?:\/(\d+))?
colors=unchanged,"\033[38;5;220m",bright_magenta
======
# IPv4 Loopback
regexp=\s+((?:127\.\d{1,3}\.\d{1,3}\.\d{1,33})|::1)
colors=unchanged,"\033[38;5;245m"
======
# IP v6
regexp=(\w+:\w+:\w+:\w+:\w+:\w+:\w+:\w+)
colors=unchanged,"\033[38;5;214m"
======
# IP v6
regexp=(\w+:\w+:\w+:\w+)::\/(\d+)
colors=unchanged,"\033[38;5;214m",bright_magenta
======
# IP v6
regexp=(\w+:\w+:\w+::\d+)
colors=unchanged,"\033[38;5;214m"
======
# IP v6 link local
regexp=(\w+::\w+:\w+:\w+:\w+)
colors=unchanged,"\033[38;5;245m",red
======
# IPv6 Loopback
regexp=(fe80::1%lo0)
colors=unchanged,"\033[38;5;245m"
======
# Drop/Block, Pass
regexp=(?:(block|drop)|(pass))
colors=default,bright_green,bright_red
======
# Drop with Any
regexp=(?:block|drop).*(any)
colors=unchanged,bright_green
======
# Pass with Any
regexp=(?:pass).*(any)
colors=unchanged,bright_red
======
regexp=\d(:+|\.)\d
colors=unchanged,"\033[38;5;242m"
======
# Protocol
regexp=\s(?:(tcp)|(udp)|((?:ipv6-)?icmp))\s
colors=default,bright_magenta,bright_cyan,green
======
# Ports
regexp=(?:port\s+=\s+|:)(\d+)\s
colors=unchanged,blue
======
# IPv6 Ports
regexp=\[(\d+)\]
colors=unchanged,blue
=======
# status
regexp=FIN_WAIT.*
colours=red
=======
# status
regexp=SYN.*?
colours=bold red
=======
# status
regexp=LISTEN(ING)?
colours=bold blue
=======
# status
regexp=TIME_WAIT
colours=bold red
=======
# status
regexp=CLOS(E(_WAIT)?|ING)
colours=red
skip=yes
=======
# status
regexp=LAST_ACK
colours=red
=======
# status
regexp=ESTAB.*?\b|CONNECTED
colours=bold yellow
=======
# status
regexp=FREE
colours=bold green
=======
# status
regexp=DISCONNECTING
colours=red
=======
# status
regexp=CONNECTING
colours=green
=======
# status
regexp=UNKNOWN
colours=blink bold red
# Root user
regexp=^(root)\s+
colors=default,"\033[41m"
======
# Program, PID, FD
regexp=^(?:\w+)\s+([-\w]+)\s+(\d+)\s+(\d+)
colors=unchanged,bright_green,"\033[38;5;245m","\033[38;5;240m"
======
# TCP 4
regexp=\s+(tcp)(4)\s+
colors=unchanged,"\033[38;5;140m","\033[38;5;220m"
======
# TCP 6
regexp=\s+(tcp)(6)\s+
colors=unchanged,"\033[38;5;140m","\033[38;5;39m"
======
# TCP 46
regexp=\s+(tcp)(4)(6)\s+
colors=unchanged,"\033[38;5;140m","\033[38;5;220m","\033[38;5;39m"
======
# UDP 4
regexp=\s+(udp)(4)\s+
colors=unchanged,"\033[38;5;120m","\033[38;5;220m"
======
# UDP 6
regexp=\s+(udp)(6)\s+
colors=unchanged,"\033[38;5;120m","\033[38;5;39m"
======
# UDP 46
regexp=\s+(udp)(4)(6)\s+
colors=unchanged,"\033[38;5;120m","\033[38;5;220m","\033[38;5;39m"
======
# All Interfaces
regexp=\s+(\*):\d+
colors=unchanged,bright_red
======
# Foreign Address for Listen only
regexp=\s+(\*:\*)
colors=unchanged,"\033[38;5;240m"
======
# Port #
regexp=:(\d+)(?:\s+|$)
colors=unchanged,bright_magenta
======
# IPv4
regexp=\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,33})
colors=unchanged,"\033[38;5;220m"
======
# IPv4 Loopback
regexp=\s+((?:127\.\d{1,3}\.\d{1,3}\.\d{1,33})|::1)
colors=unchanged,"\033[38;5;238m"
======
# IP v6
regexp=\s+(\w+:\w+:\w+:\w+:\w+:\w+:\w+:\w+):
colors=unchanged,"\033[38;5;214m"
======
# IP v6 link local
regexp=\s+(\w+::\w+:\w+:\w+:\w+)%(\w+):
colors=unchanged,"\033[38;5;238m",red
======
# IPv6 Loopback
regexp=\s+(fe80::1%lo0):
colors=unchanged,"\033[38;5;238m"
======
# IPv6 Loopback
regexp=^USER\s+COMMAND\s+PID\s+FD\s+PROTO\s+LOCAL\s+ADDRESS\s+FOREIGN\s+ADDRESS
colors=bright_white
=======
# status
regexp=FIN_WAIT.*
colours=red
=======
# status
regexp=SYN.*?
colours=bold red
=======
# status
regexp=LISTEN(ING)?
colours=bold blue
=======
# status
regexp=TIME_WAIT
colours=bold red
=======
# status
regexp=CLOS(E(_WAIT)?|ING)
colours=red
skip=yes
=======
# status
regexp=LAST_ACK
colours=red
=======
# status
regexp=ESTAB.*?\b|CONNECTED
colours=bold yellow
=======
# status
regexp=FREE
colours=bold green
=======
# status
regexp=DISCONNECTING
colours=red
=======
# status
regexp=CONNECTING
colours=green
=======
# status
regexp=UNKNOWN
colours=blink bold red
# Interface Name
regexp=^\s([-\w]+):
colors=default,bright_green
======
# Dates
regexp=(\d{4}-\d{2}(?:-\d{2})?)
colors=unchanged,bright_magenta
======
# Numbers
regexp=(\d+\.\d+)
colors=unchanged,bright_cyan
======
# MiB
regexp=(MiB)
colors=unchanged,bright_yellow
======
# MiB
regexp=(GiB)
colors=unchanged,bright_red
======
# No data
regexp=(Not enough data available yet)
colors=unchanged,"\033[38;5;242m"
# Size
regexp=(\d+(?:\.\d+)?G)
colors=default,"\033[38;5;214m"
======
# Size
regexp=(\d+(?:\.\d+)?M)
colors=default,"\033[38;5;221m"
======
# Size
regexp=(\d+(?:\.\d+)?K)
colors=default,"\033[38;5;223m"
======
# Size
regexp=\s(\d%)
colors=default,bright_green
======
# Size
regexp=\s([123]\d%)
colors=default,bright_yellow
======
# Size
regexp=\s([4-9]\d%)
colors=default,bright_red
======
# Headers
regexp=(\w+):\s+(\w+)
colors=default,bright_white, bright_yellow
======
# Headers
regexp=(errors):\s+(.*)
colors=default,bright_red, white
======
# Status
regexp=(ONLINE)
colors=default,bright_green
======
# Headers
regexp=^(NAME.*)
colors=default,bright_white
======
# Headers
regexp=(-)
colors=default,"\033[38;5;243m"
======
# History
regexp=^(\d{4}-\d{2}-\d{2})\.(\d{2}:\d{2}:\d{2})
colors=default,bright_magenta,bright_cyan
======
# Headers
regexp=(?:(create)|(destroy)|(set))
colors=default,bright_green,bright_red,bright_yellow
======
# Headers
regexp=\s+(\w+)=([^\s]+)
colors=default,blue,bright_blue
# Size
regexp=(\d+(?:\.\d+)?G)
colors=default,"\033[38;5;214m"
======
# Size
regexp=(\d+(?:\.\d+)?M)
colors=default,"\033[38;5;221m"
======
# Size
regexp=(\d+(?:\.\d+)?K)
colors=default,"\033[38;5;223m"
======
# Size
regexp=\s(\d%)
colors=default,bright_green
======
# Size
regexp=\s([123]\d%)
colors=default,bright_yellow
======
# Size
regexp=\s([4-9]\d%)
colors=default,bright_red
======
# Headers
regexp=(\w+):\s+(\w+)
colors=default,bright_white, bright_yellow
======
# Headers
regexp=(errors):\s+(.*)
colors=default,bright_red, white
======
# Status
regexp=(ONLINE)
colors=default,bright_green
======
# Headers
regexp=^(NAME.*)
colors=default,bright_white
======
# Headers
regexp=(-)
colors=default,"\033[38;5;243m"
======
# History
regexp=^(\d{4}-\d{2}-\d{2})\.(\d{2}:\d{2}:\d{2})
colors=default,bright_magenta,bright_cyan
======
# Headers
regexp=(?:(create)|(destroy)|(set))
colors=default,bright_green,bright_red,bright_yellow
======
# Headers
regexp=\s+(\w+)=([^\s]+)
colors=default,blue,bright_blue
@debdrup

This comment has been minimized.

Copy link

@debdrup debdrup commented Apr 11, 2021

If you were to continue this work, a good reference for utilities that this can be applied to would be https://man.freebsd.org/stats(7) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment