diff --git a/README.markdown b/README.markdown index 9ed041c..0f92fd9 100644 --- a/README.markdown +++ b/README.markdown @@ -26,7 +26,7 @@ Each entry consists of several lines. Each line has form: `keyword=value` -where keyword is one of: regexp, colours, command, skip, replace, count +where keyword is one of: regexp, colours, command, concat, skip, replace, count 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. @@ -44,6 +44,8 @@ This is useful on a 256-colour enabled xterm, where e.g. `colours="\033[38;5;22 **command** is command to be executed when regexp matches. Its output will be mixed with normal stdout, use redirectors (`>/dev/null`) if you want to suppress it. +**concat** is the name of a file which the current line will be appended to when the regexp matches. + **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. Default (if you do not have skip keyword) is of course not skipped. **replace** means the regular expression match will be replaced by the value. 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. diff --git a/grcat b/grcat index 4187142..d7ec1b9 100755 --- a/grcat +++ b/grcat @@ -130,7 +130,7 @@ while not is_last: keyword = lower(keyword) if keyword in ('colors', 'colour', 'color'): keyword = 'colours' - if not keyword in ["regexp", "colours", "count", "command", "skip", "replace"]: + if not keyword in ["regexp", "colours", "count", "command", "skip", "replace", "concat"]: raise ValueError("Invalid keyword") ll[keyword] = value @@ -210,6 +210,11 @@ while 1: else: prevcount = "once" pos = len(line) + if 'concat' in pattern: + with open(pattern['concat'], 'a') as f : + f.write(line + '\n') + if 'colours' not in pattern: + break if 'command' in pattern: os.system(pattern['command']) if 'colours' not in pattern: diff --git a/grcat.1 b/grcat.1 index d084fbb..80c2a0d 100644 --- a/grcat.1 +++ b/grcat.1 @@ -25,6 +25,7 @@ where keyword is one of: .BR regexp ", .BR colours ", .BR command ", +.BR concat ", .BR skip ", .BR count ". Only