The officially official Devuan Forum!

You are not logged in.

#1 2019-11-19 01:32:43

freemedia2018
Member
Registered: 2019-10-21
Posts: 66  

the benefits of highlighting console output

i do a lot of stuff on the command line, and i have a sort of swiss-army-tool with the extras i rely on most. i actually created it to help people learn a bash-like command line in windows, before migrating.

but the picture here shows the output of find piped to "fsortplus", one of the tools i use that shows filesize, sha256sums, date/time and full paths.

2Dy4vVRZ.png

what im doing is looking for any duplicates of the stylus plugin-- ive found 3.

there are various ways i can deal with the fact that all the long white-on-black text lines run together, but what i decide to do is just add rainbow -f to the pipeline.

if i was running the alex shell, i wouldnt need to call it. i could just say | rainbow -f

but since im running bash instead, i can still call the tool the way shown here.

the hashsums are trivial to distinguish in yellow. -f means "field" and there are other options for the rainbow command.

--inksearch is a multi-colour highlighter (not shown) it differs from grep in that it shows not only lines containing the search queries, it shows the surrounding lines. if you want to isolate those lines you can use egrep or isoname.

so highlight "foo" yellow, "bar" red and "baz" light blue, you would do this:

| inksearch "foo|bar|baz 14 12 9"

ordinarily i put all these tools together in one large python script. but if youd like to play with that or if youd like me to isolate either or both of those parts of the script, let me know. i havent included any of the code here, as 1. no one has asked and 2. you may want to write your own highlighter tools instead. but the code is public domain if theres any interest.


monopolies are able to change free software so it better serves their freedom than ours.

why is that so difficult to prove to many free software advocates, and what is it that stops them from caring?

Offline

#2 2020-03-25 14:00:13

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: the benefits of highlighting console output

Hello:

Sorry for reviving an oldish thread but I just came across your post.
These days I seem to have more time to read unanswered posts ....   =-/

One of the things I like of how Devuan ascii is implemented is how console output is highlighted at boot time and when using commands such as dmesg.
Unfortunately, the output of dmesg | grep whatever gets written to the terminal without any highlighting.

Is there a way to fix/change this so that anything printed to the terminal has the same highlighted output/behaves in the same manner, irrespective of whatever comes after the command line instruction?

It would be nice to have it enabled by default.

Thanks in advance,

A.

Offline

#3 2020-03-25 15:51:35

Geoff 42
Member
Registered: 2016-12-15
Posts: 461  

Re: the benefits of highlighting console output

I think that dmesg auto detects whether the output is to the screen or not and turns on colour or not!
There is a switch --color=[auto|always|never], so I think what you need is :-

dmesg --color=always | cat

Geoff

Offline

#4 2020-03-25 17:52:31

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: the benefits of highlighting console output

Hello:

Thanks for the prompt reply.

Geoff 42 wrote:

... dmesg auto detects whether the output is to the screen or not and turns on colour or not!
There is a switch --color=[auto|always|never], so I think what you need is :-

dmesg --color=always | cat

Right ...
That works ...

Using the switch the difference between sudo dmesg | grep whatever and sudo dmesg --color=always | grep whatever is that the highlighting is turned on.

Now, sudo dmesg is always highlighted but not by my using any switch so I guess there is a setting/place where that switch is applied.

Where might that setting be?

Thanks in advance,

A.

Offline

#5 2020-03-26 08:32:47

Geoff 42
Member
Registered: 2016-12-15
Posts: 461  

Re: the benefits of highlighting console output

The default is color=auto according to man dmesg. The man page also has a section on COLORS and it apparently also uses settings in /etc/terminal-colors.d/dmesg.disable. It refers us to man terminal-colors.d. It would appear that it is possible to have some control over what colours are used for different parts of the output.

I use rxvt as my terminal and it is able to display colours.

Geoff

Offline

#6 2020-03-26 10:38:12

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: the benefits of highlighting console output

Hello:

Geoff 42 wrote:

The default is color=auto according to man dmesg.

Thank you for pointing that out in such a gentle manner.
Should know better by now, must make it a point of looking through the man files before asking.  =-7

Geoff 42 wrote:

... page also has a section on COLORS ...

I'll have a good look at that and see if I can replace auto with always

Geoff 42 wrote:

I use rxvt as my terminal and it is able to display colours.

I'll check that out also.

Thanks a lot, you have been very helpful.

Cheers,

A.

Offline

#7 2020-03-29 22:05:18

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: the benefits of highlighting console output

Hello:

Altoid wrote:

I'll have a good look at that and see if I can replace auto with always.

I have not been able to find out where to change this.

As I have mentioned, the output of dmesg is highlighted but the output of dmesg | grep whatever is not.

As expected, dmesg --color=always | grep whatever is highlighted.

My reasoning is that there is a script or file somewhere that sets dmesg to dmesg --color=auto, otherwise the output would be in the default b+w.

I've looked at the dmesg and terminal-colors.d man files to no avail.

There are references to $XDG_CONFIG_HOME/terminal-colors.d or $HOME/.config/terminal-colors.d to override the global setting but what I would like to is to change the global setting from dmesg --color=auto to dmesg --color=always for all the cli utilities I use, not only dmesg.  eg: ls, dir, etc.

It seems that aliases could be generated to do that but I think it would be better to make the change globally.

Is that at all possible? 

Thanks in advance,

A.

Offline

#8 2020-03-29 23:10:17

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: the benefits of highlighting console output

Hello:

Altoid wrote:

Is that at all possible?

Finally found a clue here:
https://askubuntu.com/questions/103913/ … l-commands

The solution is within ~/.bashrc, where you have to edit this section of the script ...

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

... to get this:

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=always'
    alias dir='dir --color=always'
    alias vdir='vdir --color=always'
    alias grep='grep --color=always'
    alias fgrep='fgrep --color=always'
    alias egrep='egrep --color=always'
    alias dmesg='dmesg --color=always'
fi

Basically what this is does is generate aliases with the --color=always modifier.

From what I have read in the link, it would seem that the --color= modifier is hard coded into dmesg as well as other utilities.
eg: apparently dir does not have it but ls does.

Cheers,

A.

Offline

#9 2020-03-30 04:30:48

aus9
Member
Registered: 2020-03-24
Posts: 37  

Re: the benefits of highlighting console output

hi Altoid

I am sure Geoff 42 has a better config. I prefer lxterminal but when I use rxvt I have a home config that looks like this.

cat .Xdefaults 
! rxvt
URxvt*background: Black
URxvt*foreground: White
URxvt*geometry: 117x55
URxvt*scrollBar: true
URxvt*rightScrollBar: true

! -- Fonts -- !
URxvt.font:  xft:dejavu DejaVuSans:size=13:antialias=true
URxvt.letterSpace: -1

that is almost max the window on a monitor with 1920x1080

I stole it from someone else on a different forum.

hope that helps

Last edited by aus9 (2020-03-30 04:31:54)

Offline

Board footer