SkillAgentSearch skills...

Hl

Highlight (colorize) text data using regular expressions (efficient C program)

Install / Use

/learn @mbornet-hl/Hl
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

hl : a colorization command

Purpose

In short :

hl is a binary program compiled from C and lex source which can greatly help you read log files, the output of commands or scripts, configuration files, text files. It can highlight thresholds, colorize blocks of text delimited by markers, alternate colors when the value of an element changes (or on the contrary when it does not change), check values consistency on a line, colorize dates based on the day of the week, colorize fields of text, and so on. Many configurations have been created, and you can easily create yours to suit your needs, using simple text strings or regular expressions.

Its purpose is to colorize what is important in the text you read. It has been designed to help you get straight to the point. It's fast and efficient.

There are no need to add plug-ins when you want to colorize a new syntax : you just have to define a new configuration with basic or extended regular expressions. You don't have to install the binary nor the configuration files in a system directory, you can use environment variables to specify where to fetch the files.

Contributing

At the present time, hl has only been included in the ArchLinux distribution (see https://aur.archlinux.org/packages/hl-git/ ). There are no RPM nor .deb package, and if you want to use it, you'll have to compile it for your system (which is very easy) or just use the binary on this web site. hl would be more widely spread if it can be installed using dpkg, apt-get, rpm, or yum. So if you want to create such packages, you are welcome !

Another way to contribute is to share the configurations that you have created that could help other people. To do so, please add a small comment above your configuration to specify your name, the creation date of your configuration and its purpose, and add an example of the data (as a separate file : 50 lines max) that your configuration colorizes. You also can add a screenshot of the result of the colorization of your data. Those files will be located in a sub-directory of the examples directory.

Donation

If this software helps you, please consider donating here : https://paypal.me/MartialBornet ! Donations will encourage me to keep working on this software, fix bugs (if any), and create new configurations. This work (software and configuration) is only done during my free time. It helps me a lot, and I hope it helps you too.

Thank you.

Purpose - In more detail

This command is a compiled C program which can colorize text with up to 42 colors according to specified regular expressions. It can colorize patterns on a line when it finds a match, or colorize a group of lines from a start marker to an end marker, or alternate colors when the value of a match changes, or when it doesn't change. Configuration files can be placed anywhere on the file system (not only in /etc/default) as long as you initialize the environment variables. It uses regcomp() and regexec() to colorize (highlight) strings from stdin using options on the command line.

It can be used to colorize text files (such as log files, configuration files, source files, ...) or commands output. Here are two examples of how you can colorize the output of ls using the file date, by day (with lD) : lD

or by week (with lW) :

lW

These are examples, the dates of the listed files have been modified to give suitable results. The scripts lD and lW are available in the scripts directory, and you can modify them to change the colors to your taste.

Standard system commands can be colorized without having to change their syntax nor having to manually pipe their output to the hlcommand, using the hl_generic script. If you want to colorize the output of a command, here is what you have to do :

  1. Define a colorization configuration having the name of the command,
  2. Create a hard link on hl_generic with the name of the command,
  3. Make sure the directory containing the new link appears before the directory containing the original command in your PATH variable,
  4. Use your command the way you are used to.

hl can use up to 42 colors :

hl_colors

Articles (in french)

Here are some links to articles about hl in french magazines :

  1. Colorisez vos textes avec la commande hl
  2. Tirez parti de la colorisation pour faciliter la lecture de vos données
  3. Découvrez la puissance des nouvelles fonctions du surligneur automatique hl

Usage

hl: version 1.173
Usage: hl [-oO][-h|-H|-V|-[[%.]eiuvdDEL12345][-[rgybmcwRGYBMCWnAIsNpPxJTt] regexp ...][--config_name ...] ]
  -o  : usage will be displayed on stdout (default = stderr)
  -O  : debug messages will be displayed on stdout (default = stderr)
  -h  : help
  -H  : help + configuration names
  -V  : version
  -v  : verbose
  -u  : do not bufferize output on stdout
  -e  : extended regular expressions
  -i  : ignore case
  -E  : print on stderr
  -r  : red
  -g  : green
  -y  : yellow
  -b  : blue
  -m  : magenta
  -c  : cyan
  -w  : white
  -R  : red     (reverse video)
  -G  : green   (reverse video)
  -Y  : yellow  (reverse video)
  -B  : blue    (reverse video)
  -M  : magenta (reverse video)
  -C  : cyan    (reverse video)
  -W  : white   (reverse video)
  -n  : never colorize
  -%c : specifies the beginning of a range colorized in color 'c'
  -.  : specifies the end of the previous range
  -d  : debug
  -D  : display regular expressions
  -L  : lex debug
  -1  : color brightness (half-bright)
  -2  : color brightness (normal : default)
  -3  : color brightness (bright)
  -4  : color brightness (underscore)
  -5  : color brightness (blink, on some terminals)
  -A  : alternate colors when string matched by selection regex changes
  -I  : alternate colors when string matched by selection regex does not change
        Syntax for alternate options : -{A|I}[[s],c1c2...cn]
         where s is a number from 0 to 9 indicating the selection regexp number,
         and c1, c2, ... cn are color specifiers to use
        Alternate colors implies extended regular expressions (-e)
        Syntax for the use of a 2nd colorset triggered by another option :
         -{A|I}#a:s,c11c12...c1n:c21c22...c2p
         where s is a number from 0 to 9 indicating the selection regexp number,
         a is the number of the option that triggers the use of the 2nd colorset,
         c11c12...c1n are the colors of the 1st colorset, and
         c21c22...c2p are the colors of the 2nd colorset
  -a  : alternate colors at each match on a line
        Syntax for alternate options : -a[[s],c1c2...cn]
         where s is a number from 0 to 9 indicating the selection regexp number,
         and c1, c2, ... cn are color specifiers to use
        Alternate colors implies extended regular expressions (-e)
  -s  : alternate colors when the string matched by the selection regex is the image
        by a simple function (+, -, * or /) of the value of the previous matching string
        Syntax for sequential control option : -s[[-+*/]p[adox]:][n],c1c2...cn]
         where p is a positive integer (parameter),
         n is a number from 0 to 9 indicating the selection regexp number,
         and c1, c2, ... cn are color specifiers to use
           d : decimal (default)
           o : octal
           x : hexadecimal
           a : ascii (first character of the matching string)
        Alternate colors implies extended regular expressions (-e)
  -J  : Colorize date according to the day of the week
        Syntax for day of week option : -J[Ys1ms2ds3[,c1c2...c7]]
         where :
           s1 : number of the sub-regex for the year
           s2 : number of the sub-regex for the month
           s3 : number of the sub-regex for the day of the month
        and c1c2...c7 are the optional color specifiers for Sunday to Saturday
  -T  : Colorize string according to specified thresholds values
        Syntax for thresholds option : -Ts[x],s1[:c1],s2[:c2]...s10[:c10]
         where :
           s is a number from 0 to 9 indicating the selection regexp number,
           x indicates that thresholds are in hexadecimal
           si : value of the i-th threshold for 1 <= i <= 10
           c1 : color of the i-th range     for 1 <= i <= 10
  -t  : Colorize string according to time periods
        Syntax for time periods option : -tp[0][R][:num][:spec][,c1c2...c10]
         where :
           p is a time period specifier in [YmwdHMSun]
           0 tells that the date must be framed at the beginning of the period
           R is an optional flag telling to use an optional time reference
             instead of the current time. The optional time reference must be
             specified before the regex argument
           num is an optional number of time periods (default is 1)
           spec is a string specifying the position of date elements,
             composed of letters in [YmbdHMSus], each one followed by the
             number of the sub-regex it is associated to,
         and c1c2...c7 are the optional color specifiers for the time periods
  -N  : consistent numbering of sub-expressions in -A/-I 
View on GitHub
GitHub Stars125
CategoryDevelopment
Updated1mo ago
Forks10

Languages

C

Security Score

80/100

Audited on Feb 14, 2026

No findings