2

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 ??

  • I think grc requires python3. Do you have python3 installed on the new computer? – fd0 Oct 5 '19 at 12:27
  • @fd0 If I do a : $ which python , I get : /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin//python , Have I got to set python3 (Ihave python3.7) for current binary python ? – youpilat13 Oct 5 '19 at 12:34
  • Yes, you need to select python3.7. Are you using MacPorts? – fd0 Oct 5 '19 at 12:41
  • yes, how to switch from python3.7 for binary python ? – youpilat13 Oct 5 '19 at 12:47
  • @youpilat13 Small comment to your Update1: gcr (and its regexp) is (are) dumb. The most important components of grc are the conf.* files and the regexps inside. The regexps are primarily made for Linux & the US-locale. With an alien locale (like the french or german one) they may fail to color things as expected. The regexps won't be adjusted if you use an alien locale. So go the other way round and adjust the conf.* and its regexps. The missing group name is completely unrelated to the failing size coloring in the ls output. – klanomath Oct 12 '19 at 14:20
4
+50

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

  • ok thanks but I have only a unique file conf.ls located in /opt/local/share/grc/conf.ls. Have I got to create another conf.ls file into my $HOME/.grc/directiry ?? Or elsewhise, How to change to US date format ? my locale shows : LANG="fr_FR.UTF-8" LC_COLLATE="fr_FR.UTF-8" LC_CTYPE="fr_FR.UTF-8" LC_MESSAGES="fr_FR.UTF-8" LC_MONETARY="fr_FR.UTF-8" LC_NUMERIC="en_US" LC_TIME="fr_FR.UTF-8" LC_ALL= , i.e the same than my High Sierra version of MacOS where colors of different size appears correctly. Regards – youpilat13 Oct 11 '19 at 7:58
  • I don't understand that the original method I describe in my first post is working on High Sierra, i.e having yello/orange/red colors with different sizes (> 1 Mbyte/ >10 MB / > 100 MB) and that's not working on my new Mojave. I would like to keep my locale since I use the same on the old High Sierra macbook. I have surely forgotten something. My regexp are not correct ? If you had another tracks or clues ... Regards – youpilat13 Oct 11 '19 at 20:02
  • Thanks, my issue is not solved but I realize that something is wrong : in my "ls -l" output, there is no "group" name (normally it should appear just after the owner name of the file. Maybe the trouble comes from this missing field ? You can see it on my screen capture in my original post : I have a number instead of a group name. What di you think about ? I am going to add screen captures on my new Mojave macbook to illustrate, keeping on trying to solve it ... – youpilat13 Oct 12 '19 at 12:01
  • ok, things are better... just a last point, month "august" in french is "août", so I did : # Date-Time => G1= Day G2=Month G3=Hour G4=Minutes G5=Year regexp=([ 1-3]\d)\s([a-zû]{3})\s(?:([0-2]?\d):([0-5]\d)(?=[\s,]|$)|\s*(\d{4})) colours=unchanged,cyan,cyan,cyan,cyan,bold cyan but [a-zût]is not detected, what do you think about ? Except this, your solution is working, thanks – youpilat13 Oct 12 '19 at 15:50
  • 1
    @youpilat13 [a-z\u00FB] is the correct expression. It means all lowercase characters and the unicode character (U+00FB) which is û. If you want to add a second character simply append it e.g. ç (U+00E7): [a-z\u00FB\u00E7]. I modified the conf.ls in my answer respectively. – klanomath Oct 12 '19 at 17:34
0

I believe that grc requires python3. To change the version of python on a system with MacPorts installed, first list the available versions-

port select --list python
Available versions for python:
        none
        python26-apple
        python27 (active)
        python27-apple
        python37 

To change to python37 -

port select python python37
  • the python3 with grc 1.11 doesn't seem to produce colors code for size of files when I do : "l" which corresponds to a "ls -lrt". Are you sure that my procedure is correct from my original post ? – youpilat13 Oct 5 '19 at 13:43
  • Sorry, I do not have grc installed nor have I used the product. What is the output of the following command- head -n1 /path/to/grc . Note: replace /path/to with the real path to the application. – fd0 Oct 5 '19 at 14:11
  • $ head -n1 /opt/local/bin/grc gives : #!/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 – youpilat13 Oct 5 '19 at 14:16
  • Ok, your version of grc uses python2.7. Change python3 back to python2- port select python python27 at least until you sort out your issue. – fd0 Oct 5 '19 at 14:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .