Grc inside terminal (with different colors into terminal as a function of files size) not working on 10.14.6 Mojave and working on High Sierra 10.13.6

bashcolormojavesshterminal

I can get working the tool grc which allows to have colors for permissions and different colors as a function of the size of files listed for example with ls -l command.

On my previous MacBook with High Sierra 10.13.6, I show you an example of what I get :

grc working

As you can see, I have a colors code for the different sizes of files (increasingly white, yellow, green and red).

Now, on my new MacBook with Mojave 10.14.6, with the same ~/.bashrc and ~/.bash_profile files, I can't have the same rendering than for the High Sierra 10.13.6 MacBook pro. Here below what I get :

grc not working

You can see that no colors appear for size files (unlike the High Sierra case).

I get the same issue when I do a ssh from Mojave to High Sierra.

Here the content of ~/.bashrc on Mojave not working version :

############ dircolors binary #################
export PATH=/opt/local/libexec/gnubin:$PATH 
###############################################

export CLICOLOR=1
export LS_COLORS='README*=4;31:*.txt=1;35'
eval `dircolors ~/.dircolors`

########### GRC colourify #################
source ~/.grc/grc_bash

########### alias l #######################
alias l='grc -es --colour=auto ls --color -G -lrt'

########## function ls ####################
function ls { grc -es --colour=auto ls --color -G -C -rt "$@" | gsed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' ;}

For ~/.grc/grc_bash, I have put :

GRC="$(which grc)"
if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then
    alias colourify="$GRC -es --colour=auto"
    alias blkid='colourify blkid'
    alias nmap='colourify nmap'
    alias configure='colourify ./configure'
    alias df='colourify df'
    alias diff='colourify diff'
    alias docker='colourify docker'
    alias docker-machine='colourify docker-machine'
    alias du='colourify du'
    alias env='colourify env'
    alias free='colourify free'
    alias fdisk='colourify fdisk'
    alias findmnt='colourify findmnt'
    alias make='colourify make'
    alias gcc='colourify gcc'
    alias g++='colourify g++'
    alias id='colourify id'
    alias ip='colourify ip'
    alias iptables='colourify iptables'
    alias as='colourify as'
    alias gas='colourify gas'
    alias ld='colourify ld'
    alias ls='colourify ls'
    alias lsof='colourify lsof'
    alias lsblk='colourify lsblk'
    alias lspci='colourify lspci'
    alias netstat='colourify netstat'
    alias ping='colourify ping'
    alias traceroute='colourify traceroute'
    alias traceroute6='colourify traceroute6'
    alias head='colourify head'
    alias tail='colourify tail'
    alias dig='colourify dig'
    alias mount='colourify mount'
    alias ps='colourify ps'
    alias mtr='colourify mtr'
    alias semanage='colourify semanage'
    alias getsebool='colourify setsebool'
    alias ifconfig='colourify ifconfig'
fi

with ~/.grc/grc.conf :

(^|[/\w\.]+/)semanage fcontext\s?
conf.semanagefcontext
(^|[/\w\.]+/)semanage (user|login|port)\s?
conf.semanageuser

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

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

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

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

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

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

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

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

# apache ant command
(^|[/\w\.]+/)ant\s?
conf.ant

# # apache maven command
(^|[/\w\.]+/)mvn\s?
conf.mvn

At first sight, where could error come from ? Maybe I have forgotten an environment variable or an unsupported option for ls -lrt that would prevent the colors code for size of files …

Any remark is welcome, Regards

UPDATE 1:

As you can see, I did a :

|fab@astro|14:03:19|~/temp| alias l
alias l='grc -es --colour=auto ls --color -G -lrt'

which shows exactly the alias for command "l"

From the screen cpature below, the I realized that I have no group name following normally following the name of owner (due to -G flag). @klanomath, Relatively to your screen capture and example, do you think my issue comes from this missing field ?

Indee, on your screen capture, you have a name of group, it may produce missing colors with grc and its regexp used by default ?

no group name ??

Best Answer

The size coloring function of the gcr ls command is still working with Mojave. You've changed the date format in the shell from month/day/(year)/time (US) to day/month/(year)/time (mostly Europe) though.

Now the day (1-31) will be colored with the default "size" color (black in my example and white in your example) as all sizes below 1M.

So either return to the US date format, or modify the respective regex expression(s) in conf.ls.

Proof:

US:

example screenshot us

Europe:

example screenshot europe

To get different colors for smaller sizes (i.e. sizes below 1M) I added the following lines to grc's conf.ls file (the regular expressions below aren't really worked out properly - the alternative way to detect the size pattern (|\d(?:[,.]?\d+)?[K]) isn't correct, so don't just copy & paste them - but they work for the example screenshots:

# size: 10 <= size < 100
regexp=\s+(\d{2}|\d(?:[,.]?\d+)?[K])(?=\s[A-Z][a-z]{2}\s)
colours=bold yellow
=======
# size: 100 <= size < 1k
regexp=\s+(\d{3}|\d(?:[,.]?\d+)?[K])(?=\s[A-Z][a-z]{2}\s)
colours=red
=======
# size: 1k <= size < 10k
regexp=\s+(\d{4}|\d(?:[,.]?\d+)?[K])(?=\s[A-Z][a-z]{2}\s)
colours=bold red
=======
# size: 10k <= size < 100k
regexp=\s+(\d{5}|\d+(?:[,.]?\d+)?[K])(?=\s[A-Z][a-z]{2}\s)
colours=green
=======
# size: 100k <= size < 1M
regexp=\s+(\d{6}|\d+(?:[,.]?\d+)?[K])(?=\s[A-Z][a-z]{2}\s)
colours=bold green
=======
# size: 1M <= size < 10M
regexp=\s+(\d{7}|\d(?:[,.]?\d+)?[KM])(?=\s[A-Z][a-z]{2}\s)
colours=yellow
=======

The exemplary regular expression regexp=\s+(\d{5}|\d+(?:[,.]?\d+)?[K])(?=\s[A-Z][a-z]{2}\s) means the following:

  1. \s+(\d{5}|\d+(?:[,.]?\d+)?[K]): search for a pattern with 1 or more non-printing characters, 5 digits (eg 34249) or 1 or more digits followed by an optional , or ., more optional digits and a K (e.g. 10K or 13.1K)

which must be followed by (?=...):

  1. \s[A-Z][a-z]{2}\s which is the pattern for an abbreviated month surrounded by one non-printing character on each side(e.g. Oct )

With the european date format active the condition won't be fulfilled because the day (one or two digits) follows after the file size. Instead the day and month would meet the requirements, if a day had five digits.


Here is a conf.ls which should work with the all french locale in Mojave's terminal. I added some working date coloring because the (french) month apparently changed to all lowercase in Mojave. You can simply remove size coloring for smaller file sizes by deleting the respective lines or change colors if you don't like them.

# The following matches file sizes as produced by ls -l or ls -lh
# The output produced by ls -s is probably not specific
# enough to be reliably matched, especially considering ls -s(k|m|g|G).
#
# Example lines:
# -rw-r--r--   1 user staff 344M Mar 22 22:51 MVI_8735.m4v
# -rw-r--r--   1 user staff 360050327 Mar 22 22:51 MVI_8735.m4v
# -rw-r--r--.  1 user staff 1.0G Nov 23 16:13 testg
# -rw-r--r--.  1 user staff 1.0K Nov 23 16:13 testk
# -rw-r--r--.  1 user staff 1.0M Nov 23 16:13 testm
# -rw-r--r--.  1 user staff 1073741824 Nov 23 16:13 testg
# -rw-r--r--.  1 user staff       1024 Nov 23 16:13 testk
# -rw-r--r--.  1 user staff    1048576 Nov 23 16:13 testm
#
# The regexp uses lookahead to match a date following the size

# size: 10 <= size < 100
regexp=\s+(\d{2})(?=\s([ 1-3]\d)\s)
colours=bright_yellow
=======
# size: 100 <= size < 1k
regexp=\s+(\d{3})(?=\s([ 1-3]\d)\s)
colours=yellow
=======
# size: 1k <= size < 10k
regexp=\s+(\d{4}|\d(?:[,.]?\d+)?[K])(?=\s([ 1-3]\d)\s)
colours=bold yellow
=======
# size: 10k <= size < 100k
regexp=\s+(\d{5}|\d\d(?:[,.]?\d+)?[K])(?=\s([ 1-3]\d)\s)
colours=red
=======
# size: 100k <= size < 1M
regexp=\s+(\d{6}|\d\d\d(?:[,.]?\d+)?[K])(?=\s([ 1-3]\d)\s)
colours=bold red
=======
# size: 1M <= size < 10M
regexp=\s+(\d{7}|\d(?:[,.]?\d+)?[KM])(?=\s([ 1-3]\d)\s)
colours=green
=======
# size: 10M <= size < 100M
regexp=\s+(\d{8}|\d\d(?:[,.]?\d+)?M)(?=\s([ 1-3]\d)\s)
colours=bold green
=======
# size: 100M <= size < 1G
regexp=\s+(\d{9}|\d{3}M)(?=\s([ 1-3]\d)\s)
colours=blue
=======
# size: 1G <= size
regexp=\s+(\d{10,}|[\d.,]+G)(?=\s([ 1-3]\d)\s)
colours=bold blue
=======
# device major minor numbers
regexp=\s(\d+),\s+(\d+)\s
colours=default,bright_yellow ,yellow
=======
# Date-Time => G1=Day G2=Month G3=Hour G4=Minutes G5=Year
regexp=([ 1-3]\d)\s([a-z\u00FB]{3})\s(?:([0-2]?\d):([0-5]\d)(?=[\s,]|$)|\s*(\d{4}))
colours=unchanged,cyan,cyan,cyan,cyan,bold cyan
=======
# root
regexp=\s(root|wheel)(?=\s|$)
colours=unchanged,bold white on_red
=======
# SELinux
regexp=(\w+_u):(\w+_r):(\w+_t):(\w\d)
colours=default,green,yellow,cyan,magenta
-
# -rwxrwxrwx ============================
# File Type
regexp=(-|([bcCdDlMnpPs?]))(?=[-r][-w][-xsStT][-r][-w][-xsStT][-r][-w][-xsStT])
colours=unchanged,unchanged,bold white
-
# owner rwx
regexp=(?<=[-bcCdDlMnpPs?])(-|(r))(-|(w))(-|([xsStT]))(?=[-r][-w][-xsStT][-r][-w][-xsStT])
colours=unchanged,unchanged,bright_green,unchanged,bright_green,unchanged,bright_green
-
# group rwx
regexp=(?<=[-bcCdDlMnpPs?][-r][-w][-xsStT])(-|(r))(-|(w))(-|([xsStT]))(?=[-r][-w][-xsStT])
colours=unchanged,unchanged,yellow,unchanged,yellow,unchanged,yellow
-
# other rwx
regexp=(?<=[-bcCdDlMnpPs?][-r][-w][-xsStT][-r][-w][-xsStT])(-|(r))(-|(w))(-|([xsStT]))
colours=unchanged,unchanged,bright_red,unchanged,bright_red,unchanged,bright_red
-
# sStT all
regexp=(?<=[-bcCdDlMnpPs?])[-r][-w]([sStT])[-r][-w]([sStT])[-r][-w]([sStT])
colours=unchanged,bold green,bold yellow, bold red
-
# ACL
regexp=^\S{10}(\+)
colours=unchanged,on_cyan bold white

Example screenshot:

example screenshot