clide - Man Page
color and style highlighting program for text
Synopsis
clide [options] [file1] [file2] [...fileN]
| clide [options] (STDIN through pipe)
clide [options] (STDIN. Use Ctrl-D to finish input)
Description
clide is a program that allows you to colorize and add various display altering attributes to text based on search patterns and expressions. Currently the focus is on creating ANSI color and style escape codes for use in terminal displays.
Options
-h, --help - Show some terse help for the program -e, --expression <expression>,<attributes> Examples: -e /searchpattern/,fg=red,bold -e HTMLTAG,fg=blue,bg=yellow -d, --definitionfile <file> -f, --expressionfile <file> --highlight, --hl <word1>[,word2,word3,...] - Quickly highlight the words given in the comma seperated list of words. --highlightattributes, --ha <attribute1>[,attribute2,attribute3,...] The default attributes used by the highlight option. This option uses the same comma seperate values taht can be defined in an normal expression. --listcolors - Show a list of foreground and background colors that can be used. --liststyles - Show a list of styles that can be used (not all of which may work on your display) --listdefinitions - Show a list of predefined search expressions --reverseprecedence, -r - Reverse the precedence order in which expressions are run through. --wf, --warmfuzzy "<message>" - Send the developer a short message to let him know that you like this program.
Examples
File Arguments
One way to utilize clide is to process the contents of a file or multiple files. This is done simply by passing the files as arguments after the other options you wish to specify for matching expressions:
clide -e HTMLTAG,fg=yellow index.html
Pipelines
Another way to use clide is by passing the output of one program into it. You are sending the standard output (STDOUT) of one program to the standard input (STDIN) of clide. Like this command that sends the output of ls through clide, which colors lines that are directory entries:
ls -l | clide -e /^d.*/,fg=blue,bold
Shell Escaping
If you are creating more complex search patterns, you are probably going to need to put quotes around the whole argument that is passed to a -e option. This is because your shell will interpret certain characters like (, ), $, &, [, ], etc. For example, this command uses an expression that will change the percentage display of a filesystem to red if it is 94% or more:
df -h | clide -e "/(100|9[4-9])%/,fg=red,bold"
But because ( ) is used in most shells as a subshell sequence, you have to put quotes around the whole expression so that its not processed by your shell.
Expressions
Expressions can be specified on the command line using one or more -e options. You can also use the -f option one or more times to specify premade expression files.
Quick Highlighting
If you're in a hurry and don't want to come up with an expression for matching words or characters that you'd like to highlight, you can use the --highlight option along with a comma seperated list of values you want to match. Like this:
clide --highlight car,truck,boat insurance-readme.txt
By default clide will highlight these words in yellow. you can override this with the --highlightattributes option, specifying what you want in the same way you would pass attribute arguments in a -e argument.
You can use the --highlight option in combination with -e of -f options, but the expressions will be applied after the expressions specified with -e or -f.
Perl Regular Expressions
clide works by passing the expression that you specify into a PERL matching operator. This means that you can pass almost any valid PERL regular expression to clide and it should work as expected.
The only limitation is in what flags you can pass to the search. Currently, you can only pass a 'i' (case insensitive) and/or a 'g' (global search) flag to the search expression. The multiline flag 'm' is not supported.
For more information about perl regular expressions, see the pcre(1) man page.
Regular Expression Search
The basic way to tell clide what text you want to affect is to use the regular expression search operator. This is passed to the -e option along with a command seperated list of attributes to set.
clide -e /failed/i,fg=yellow,bg=red,bold
The above expression searches for the word failed (using the i option after the second / means make the search case insensitive). It will change the word failed to have a foreground color of bold yellow (bright) and a background color of red.
Predefined Search Patterns
A list of helpful predefined search patterns is included with clide to make pattern matching easier for the user. A list of the patterns is available by running clide with the --listdefinitions option. You can also put your own definitions in files and use the -f option to include them.
Using a predefined search expression is simply a matter of using its name for the first part of the -e argument, like this:
clide -e HOSTNAME,bold logfile.txt
WARNING: Predefined search patterns MUST use all uppercase names. In the future clide may have other expression functions that start with lower case letters and there needs to be a way to differentiate between a pattern definition and an operation.
File Formats
NOTE: The author would like to encourage you to put your expression and definition files in a directory called .clide in your home directory. Future versions of clide may make it easier to use these files if you have them located in such a named directory.
Expression File
The expression file is pretty simple, you put each expression one per line in exactly the same way that you would pass it to the -e option. expression definitions can be used as the expressions themselves are parsed after all the predefined expressions are read in. You can include these files using the -f option.
So an expression file called microblogging might look like this:
HTMLTAG,fg=red,bg=black URL,fg=yellow,bold,underline TWITTERGROUP,fg=blue,bold # Highlight some of my MB account names /@(mkrenz|climagic|suso)/,fg=yellow,bg=blue,bold TWITTERMENTION,fg=cyan IDENTICAGROUP,fg=blue,bold
Then you'd use it like this:
twidge lsrecent | clide -f ~/.clide/microblogging
Comments can be made using a # character at the beginning of the line.
Definition File
The definition file has a bit more of a format to it. Each line has two columns seperated by whitespace. The first column is the name of the definition in all uppercase letters. The second column is the search expression starting with a forward slash and terminated by a forward slash and one or more pcre flags (i or g)
# These are IPs I'm watching out for. INTERESTINGIPS /\b(3\.14\.159\.26|206\.97\.64\.[29]|10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\b/g # Words I care about. LOGINWORDS /(error|failed|failure|success|successful)/gi
Then just include the file using -d for each file you want to include.
Note that you don't need to escape or backslash as much in the searches when you put them in a file as compared with when you specify the pattern on the command line. Keep this in mind if you copy and paste your expressions into a file.
Bugs and Limitations
Because one expression matching will actually alter the line in order to add the escape sequences, matching expressions that are run later may not match what the user expects them to match because the string has changed. This is going to be fixed in a future release.
Currently clide can only work on 7-bit ASCII text. If it encounters a line with upper 8-bit (binary) characters, it will simply print the line with out doing any processing on it. If you're really curious as to why, you can read the comments in the code or ask the author. A future version of clide may not have this limitation.
Most terminal emulators and the console itself have some limitations as to what they can display. Most of them don't support blinking text, only some support dark mode, etc. This is not a limitation of clide, it is your terminal software.
clide doesn't support multiline matching at this time.
See Also
pcre
Warmfuzzy
If you like clide, you should let the author know by sending a short message using the --warmfuzzy option, like this:
clide --warmfuzzy "I like clide"
This option makes an HTTP request to a website that will in turn let the author know what you thought.
I included this option because I think that open source projects need an easier way for users to give the developers a little reward for their efforts.
Copyright
This code is copyright 2010 by Mark Krenz under the terms of the GNU GPL version 3. See the file COPYING that comes with clide for more details.
More Info
You can find more information about clide at its website at
L<http://suso.suso.org/xulu/clide>
If you'd like to get involved with development in any way, please feel free to contact the author.
Author
clide was written by Mark Krenz <mark@suso.com>