mbornet-hl / hl

Highlight (colorize) text data using regular expressions (efficient C program)
Other
118 stars 9 forks source link

[Feature request] color=auto mode #27

Open tkapias opened 1 year ago

tkapias commented 1 year ago

I would like to include hl in aliases to provide an output like color=auto in some binutils which lack colors.

But, it needs to detect that the output is in a pipe or not in a terminal and disable the coloration.

Manualy, I do it like that:

hlauto () {
  if [ -t 1 ]; then
    hl $1
  else
    cat -
  fi
}

alias df='df -Tha --total | hlauto --df'

It works great. The new alias df ouput in color, but df | less output without hl.

Would it be easy to include this feature in hl? Maybe like this?

alias df='df -Tha --total | color=auto hl --df'
mbornet-hl commented 7 months ago

Hello, thank you for your suggestion, I've added this to my "to do" list, but I'm VERY busy at the moment. I've just thought about it and I think I've found a simple way to do this. But I need some time to implement and test it.

Regards, Martial