NAME
hl - terminal patterns highlighter
SYNOPSIS
hl [global-options] [highlight-options [patterns] ...] [- file1 [file2] ...]
DESCRIPTION
hl reads text from list of files or stdin and prints it on the console with specified patterns highlighted using terminal color escape sequences. Patterns are intrinsically perl-compatible regular expressions.
Global options are processed internally by hl whereas highlight options are passed into Term::Highlight module, therefore they should not mix. The first occurrence of an option which are not recognized as global is regarded as the beginning of highlight options. Highlight options can be explicitly separated from global options with option '--' (must not be confused with option '-' that separates list of files from highlight options).
Global options:
- -s <snippet>
-
loads a snippet with specified name from ~/.hlrc file. The white space between '-s' and the name of snippet can be omitted. For example -sW will load snippet with name 'W'.
- -g (-grep)
-
prints only lines which match specified patterns.
- -r
-
greps recursively, implies '-g'. If file list is empty starts search in current directory.
- -l
-
prints the list of files where matches were found, implies '-g'.
- -u (-utf8)
-
enables matching of Unicode characters from UTF-8 encoded input. For instance matching of '\x{239C}' will not work without this option.
- -b (-bin)
-
enables processing of binary files (not enabled by default).
- -d (-debug)
-
turns on debug support (colors printed out as symbolic sequences).
- --
-
explicitly separates global and highlight options
- -h (-help)
-
prints this message and exit.
Highligh options:
- -x[xx][.b]
-
highlights following patterns with color defined by number x[xx]. x[xx] is color id corresponding to terminal color escape sequence number and should range within [0..255]. b is 0 or 1, .0 applies the color id to foreground, .1 - to background, .0 is default value and may be omitted. If your terminal does not support 256 colors valid color ids are [0..15]. Note: if your terminal is 256 colors capable better use [16..255] colors! To see how many colors your terminal supports use tput colors command.
- -i
-
sets ignorecase search.
- -ni
-
unsets ignorecase search.
- -b
-
sets bold font.
- -rfg
-
resets foreground color to default value.
- -rb
-
resets bold font to normal.
- -rbg
-
resets background color to default value.
- -r
-
resets both background color and bold font.
- -ra
-
resets all settings to default values.
Option '-'
is used to separate list of files to process from global and highlight options. This is necessary option when reading from files due to the fact that hl can be fed with list of files or from stdin or pipe.
Highlight options apply to following them regexp patterns if any. If trailing highlight options are not followed by patterns they apply to whole text.
It is possible to define common highlight options on session level. hl supports environment variable HL_INITSTRING which value will be prepended to any highlight options given in command line.
ENVIRONMENT VARIABLES
- HL_INITSTRING
-
defines common highlight options which will be prepended to any highlight options given in command line. For example setting HL_INITSTRING="-21 -i" will make hl highlight patterns with blue (color id 21) and ignore case of them without explicit definition of highlight options in command line. Note: HL_INITSTRING must not contain global options!
EXAMPLES
ls | hl -b -46.1 -21 '\bw.*?\b'
reads output of ls command and highlight words starting with w with bold blue (color id 21) foreground and green (color id 46) background.
FILES
~/.hlrc
currently this file may contain only snippets that can be loaded with '-s' option. The format of the snippet line is
snippet name highlight_options
where snippet is a keyword, name is the name of the snippet and highlight_options contains highlight options possibly preceded by the global option '-u'. Here is an example of snippet which can be used to highlight words that start with capital letter:
snippet W -130 (?:^|[\s])[A-Z]\S+
Lines that do not match the snippet line pattern are ignored. Arguments of highlight_options are naturally split by whitespaces. If you want to have whitespaces inside patterns you can use single quotes surrounding them. Single quote itself must be prepended by backslash. Too long lines can be split into multiple lines using backslash.
SEE ALSO
Term::Highlight(3), tput(1)
AUTHOR
Alexey Radkov <alexey.radkov@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by A. Radkov.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.