Replacement is done by re.sub(), therefore you can use anything python supports - in particular, \1, \2 etc. All the preceeding regular expressions will be evaluated against the original text, but if they match and the replacement changes the length of the text, the colouring will stay at the same positions, which is probably not what you want - therefore put the replace rule preferrably at the beginning of config file.Īll the following regular expressions will be evaluated against the replaced text, not the original. Replace means the regular expression match will be replaced by the value. Default (if you do not have skip keyword) is of course not skipped. Skip can be skip=yes, if that case the matched line is skipped (discarded from the output), or skip=no, when it is not skipped. Its output will be mixed with normal stdout, use redirectors ( >/dev/null) if you want to suppress it.Ĭoncat is the name of a file which the current line will be appended to when the regexp matches. This is due to my laziness :-)Ĭommand is command to be executed when regexp matches. Caveat: the string cannot contain a comma. colours="\033[38 5 22m" will give you a dark green (inspired by Rutger Ovidius). This is useful on a 256-colour enabled xterm, where e.g. The string will be eval'ed, so you can use usual python escape sequences. This string will be inserted directly into the output in front of the matching expression. Yet another special name is an arbitrary string enclosed in straight quotes. If you use special colour name "previous", colour of the previous line of text will be used (actually, if both the first and last character of the previous line are of different colour than the default one, colour of the first one will be used).Īnother special colour name "unchanged" will leave the colour unchanged, useful if you need some context for matching regular expression and you want to leave the colour of context unchanged. Regexp is the regular expression to match.Ĭolours is the list of colours, separated by commas (you can specify only one colour), each colour per one regexp group specified in regexp. Only regexp is mandatory, but it does not have much sense by itself unless you specify at least a colour, skip, replace or command keyword as well. Where keyword is one of: regexp, colours, command, concat, skip, replace, count Lines beginning with # or empty lines are ignored. If the file is not found, it is assumed to be an absolute path of a configuration file located elsewhere.Ĭonfiguration file consists of entries, one per regexp, entries are separated with lines with first character non-alphanumeric (except #). Grcat takes as a parameter the name of configuration file.ĭirectories ~/.grc/, /usr/local/share/grc/, /usr/share/grc/ are searched for the file (in this order). taking standard input, colourising it and writing to standard output. The main is grcat, which acts as a filter, i.e. Two programs are provided: grc and grcat. Being overflooded with different logfile colo(u)?ri(s|z)ers, colortails, gccolors, colormakes and similar programs for making text files or outputs of different programs more readable by inserting ansi colour control codes into them, I decided to write my very own colouriser, eventually providing the functions of all those others.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |