Merge from garabik/grc

This commit is contained in:
Isaias Pina 2017-02-28 11:20:35 -06:00
commit ff14ccb730
24 changed files with 510 additions and 130 deletions

49
CREDITS
View File

@ -1,11 +1,44 @@
Credits where credits are due:
These people helped me with ideas, support and other things:
Piotr Klaban <makler@man.torun.pl>
Jason Tackaberry <tack@linux.com>
Eivind Tagseth <eivindt@multinet.no>
Edward Betts <edward@debian.org>
Joey Hess <joey@kitenet.net>
Miguel Gualdron <mig@anet.com>
Daniel Kollar <dkollar@fmph.uniba.sk>
Christian Zuckschwerdt <zany@triq.net>
Piotr Klaban
Jason Tackaberry
Eivind Tagseth
Edward Betts
Joey Hess
Miguel Gualdron
Daniel Kollár
Christian Zuckschwerdt
Paul Oppenheim
Emanuele Aina
April Arcus
Justin J. Novack
Ben Hoskins
Nikolay Kolev
Juraj Bednar
Francisco De Lozanne
Duncan Overbruck
delphinus
Aditya Bhargava
Cemil Browne
Ruben Barkow
Efreak
Alexander Kuntashov
Isaias Piña
Andrew Wong
Max
Pavel Vishnyakov
tomaszn
Nicolas Leclercq
Dave Wikoff
richi235
Ricardo J. Barberis
Joe Block
iamoverit
Oxicode
Jonas Minnberg
alcik
Henry Eklind
Justin Lecher

19
INSTALL
View File

@ -5,13 +5,13 @@ Radovan Garabík <garabik @ kassiopeia.juls.savba.sk>
http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
===================================================================
Requirenments:
anything with python interpreter, with more or less work needed
Requirements:
Anything with a python interpreter, with more or less work needed
if it is not unix.
If you have debian system with all necessary packages installed, type
dpkg-buildpackage (or dpkg-buildpackage -rfakeroot) in the package's
directory, then type
If you have a debian system with all necessary packages installed, type
dpkg-buildpackage (or dpkg-buildpackage -rfakeroot) in the package's
directory, then type
dpkg -i ../grc*deb
else:
@ -26,7 +26,10 @@ else:
4) read the README and manual pages
5) modify /etc/grc.conf if you feel like it
there is a small shell script called install.sh provided, which does
automatically do the above.
There is a small shell script called install.sh provided, which
automatically does the above steps.
If you're on OS X and using Homebrew,
brew install grc

View File

@ -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.

46
conf.ant Normal file
View File

@ -0,0 +1,46 @@
# ant grc colorizer configuration
# BUILD FAILED
regexp=BUILD FAILED
colours=bold red
count=more
==============
# BUILD SUCCESSFUL
regexp=^BUILD SUCCESSFUL
colours=bold green
count=more
==============
# Total time
regexp=^(Total time: )([\d]+.*)$
colours=yellow,bold magenta
count=more
===============
# some error
regexp=[\d]+ error[s]?
colours=red
count=more
==============
# some warning
regexp=[\d]+ warning[s]?
colours=yellow
count=more
===============
# some error
regexp=[Ee]rror:
colours=red
count=more
==============
# some warning
regexp=[Ww]arning:
colours=yellow
count=more
==============
# project name
regexp=^[^:\s]+:$
colours=green
count=more
==============
# products
regexp=[^/]+\.[ewrj]ar$
colours=blue
count=more

View File

@ -1,14 +1,27 @@
regexp=^checking
# cache functions
regexp=\b(loading|updating|creating) cache\b
colours=yellow bold
.........
# checking
regexp=\bchecking\s*(for|if|whether|command|how|that)?(\s*to)?\b
colours=bold blue
.........
# result is complex
regexp=\.\.\. .*$
colours=bold yellow
.........
regexp=\.\.\. yes$
# check succeeded
regexp=\.\.\.( \(cached\))? yes$
colours=bold cyan
.........
regexp=\.\.\. no$
# check did not succeed
regexp=\.\.\.( \(cached\))? no$
colours=bold red
.........
regexp=\.\.\.[ ]
# ... should be normal
regexp=\.\.\.
colours=default
.........
# creating stuff
regexp=\bcreating\b
colours=green

View File

@ -2,6 +2,10 @@
regexp=(?:\s|^)(REPOSITORY|TAG|IMAGE ID|CREATED|SIZE)(?:\s|$)
colours=default,underline
=====
# REPO, TAG
regexp=^([a-z]+\/?[^\s]+)\s+([^\s]+)
colours=default,bold white,cyan,bold black
=======
# REPO, TAG, IMAGE ID
regexp=^([a-z]+\/?[^\s]+)\s+([^\s]+)\s+(\w+)
colours=default,bold white,bright_cyan,bright_black
@ -19,29 +23,21 @@ regexp=^<none>.*$
colours=bold red
=====
# Size 'K'
regexp=\s\d*[\.,]?\d*\s(KB?|B)
regexp=\s\d*[\.,]?\d*\sKB?
colours=green
======
# Size 'M'
regexp=\s\d*[\.,]?\d*\sMB?
# Size 'M', 2 digits
regexp=\s\d{1,2}[\.,]?\d*\sMB?
colours=green
======
# Size 'M' 3+ digits
regexp=\s\d{3,4}[\.,]?\d*\sMB?
colours=yellow
======
# Size 'G'
regexp=\s\d*[\.,]?\d*\sGB?
colours=red
=====
# CREATED hours
regexp=\s+\d+\shours\s\w+
colours=bright_green
======
# CREATED days
regexp=\s+\d+\sdays\s\w+
colours=green
======
# CREATED weeks
regexp=\s+\d+\sweeks\s\w+
colours=yellow
======
# CREATED months
regexp=\s+\d+\smonths\s\w+
colours=red
# Date Ago
regexp=(?:\s{2}|^)(?:\w+\s)+ago
colours=cyan

View File

@ -1,31 +1,34 @@
# HEADERS
regexp=(?:\s|^)(CONTAINER ID|IMAGE|COMMAND|CREATED|STATUS|PORTS|NAMES)(?:\s|$)
# This is for docker ps and docker-compose ps
# Headers
regexp=(?:\s{2}|^)(CONTAINER ID|IMAGE|COMMAND|CREATED|STATUS|PORTS|NAMES|Name|Command|State|Ports)(?:\s|$)
colours=default,underline
======
# IMAGE
regexp=^(?!CONTAINER)(\w+)\s+([^\s]+)\s+(".*")\s+(.*(?=(?:Up|Exited|Created|Restarting)))
colours=default,bright_black,bold white,bright_black,cyan
# Commands (docker ps)
regexp=(?:\s{2}|^)(?:\s\")(.*)(?:\")(?:\s{2}|$)
colours=magenta
=======
# Date Ago (docker ps)
regexp=(?:\s{2}|^)(?:\w+\s)+ago
colours=cyan
======
# Statuses - Created
regexp=\sCreated\s
colours=blue
======
# Statuses - Up / Restarting
regexp=\sUp\s(\d+|\w+)\s\w+(?:\s\w+)?
# Statuses
# https://github.com/docker/docker/blob/e5a3f86e447dd659da3c2e759f3c088a0bfcfe3d/container/state.go#L40
# Up
regexp=(?:\s{2}|^)(?:Up|Restarting)(?:(?:\s[\w,\d,(,)]+)+)?
colours=bold green
======
# Statuses - Exited
regexp=\sExited\s.(\d+).\s.+ago
colours=bold red,red
======
# Statuses - Restarting
regexp=\sRestarting\s.(\d+).\s.+ago
colours=bold blue
======
# Exited
regexp=(?:\s{2}|^)(?:Exited|Exit|Dead|Removal In Progress)(?:(?:\s[\w,\d,(,)]+)+)?
colours=bold red
=======
# Ip Addresses / Ports
regexp=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\:)?(\d{1,5}))?(?:->)?(\d{1,5}(\/)\w+)
colours=default,blue,default,bright_green,bright_blue,default
======
# NAMES
regexp=(?:([a-z\-_0-9]+)/)*([a-z\-_0-9]+)$
colours=default,yellow,bold yellow
regexp=(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\:)?(\d{1,5}))?(->)?(\d{1,5})(\/)(\w+)
colours=blue,default,bright_green,default,bright_green,default,bright_blue
=======
# Name and command in docker-compose ps.
regexp=(?:\s{2}|^)(?:[a-z\-_0-9]+)(?:\s{2}|$)(?:\s+(.+?)\s{2,})?
colours=bold yellow,magenta
=======
# Container ID / Image ID and Image. Need to be together to override the "name" regex.
regexp=(?:\s{2}|^)([a-z0-9]+)\s{2,}((?:(?:[a-z\-_0-9\.]+)+(\/|:)?)+)
colours=default,cyan,default

View File

@ -1,7 +1,7 @@
#
regexp=\bgcc\b
colours=yellow
count=more
regexp=\b(g?cc|[gc]\+\+|g?as|ld)\b
colours=white bold
count=once
.........
#
regexp=^[^:\s]*?:\d+:
@ -15,6 +15,10 @@ count=once
regexp=\`[A-Za-z0-9_():&*]+( const)?\'
colours=magenta
.........
# compilation method modifiers
regexp=\s\-(O\d?|f\S+|pthread|g\S*|c|W\S,\S+)\b
colours=yellow
.........
# -O
regexp=\-O\d
colours=green
@ -27,7 +31,7 @@ colours=yellow
# stderr to grcat
#
# warning
regexp=warning:.*
regexp=[Ww]arning[:\b]
colours=white
.........
regexp=warning:
@ -35,7 +39,7 @@ colours=bold yellow
count=once
.........
# error
regexp=error:.*
regexp=[Ee]rror[:\b]
colours=bold white
.........
regexp=error:

44
conf.ip Normal file
View File

@ -0,0 +1,44 @@
# IP4
regexp=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
colours=bold yellow
-
# IP6
regexp=[0-9a-fA-F]{0,4}(\:\:?[0-9a-fA-F]{0,4})+?(\/\d{1,3})
colours=yellow
-
# MAC
regexp=(\d|[a-f]){2}(\:(\d|[a-f]){2}){5}
colours=magenta
-
# parenthesis
regexp=\(|\)
colours=yellow
-
# dev wlan0 etc
regexp=dev \w+
colours=yellow
-
# "default"
regexp=default
colours=on_blue
-
# ip range size
regexp=/\d{1,2}
colours=red
-
# "linkdown"
regexp=linkdown
colours=bold red
-
# "src"
regexp=src \S+
colours=on_magenta

View File

@ -1 +0,0 @@
conf.mount2

11
conf.mount Normal file
View File

@ -0,0 +1,11 @@
# Intended for colouring 'mount' output
# written by Emanuele Aina
regexp=^(.*) on (.*) type (.*) \((.*)\)
colours=default,green,yellow,blue,magenta
=====
regexp=^cgroup.*
colours=bright_black
=====
regexp=^tmpfs.*
colours=bright_black

View File

@ -1,11 +0,0 @@
# Intended for colouring 'mount' output
# written by Emanuele Aina
regexp=^(.*) on (.*) type (.*) \((.*)\)
colours=default,green,yellow,blue,magenta
=====
regexp=^cgroup.*
colours=bright_black
=====
regexp=^tmpfs.*
colours=bright_black

92
conf.mvn Normal file
View File

@ -0,0 +1,92 @@
# mvn grc colorizer configuration
# [INFO]
regexp=^\[INFO\]
colours=bold
count=more
==============
# [WARNING]
regexp=^\[WARNING\]
colours=bold yellow
count=more
==============
# [ERROR]
regexp=^\[ERROR\]
colours=bold red
count=more
==============
# BUILD FAILURE
regexp=BUILD FAILURE
colours=bold red
count=more
==============
# [debug]
regexp=^\[debug\]
colours=magenta
count=more
==============
# lines [INFO] ----
regexp=\s[-]{6,}
colours=red
count=more
==============
# lines ^----
regexp=^[-]{6,}
colours=yellow
count=more
==============
# lines T E S T S
regexp=^ T E S T S
colours=yellow
count=more
==============
# lines ^Tests run:
regexp=^Tests run: ([\d]+)
colours=yellow,green
count=more
==============
# lines ^Tests run: Failures/Errors/Skipped
regexp=(Failures|Errors|Skipped):\s([\d]+)
colours=none,yellow,bold red
count=more
==============
# lines ^Tests run: Failures/Errors/Skipped
regexp=(Failures|Errors|Skipped):\s(0)\D?
colours=none,yellow,green
count=more
==============
# summary
regexp=\s(Total time: )(.*)$
colours=none,none,bold yellow
count=more
==============
# summary
regexp=\s(Finished at: )(.*)$
colours=none,none,bold yellow
count=more
==============
# BUILD SUCCESSFUL
regexp=\s(BUILD SUCCESSFUL)
colours=none,green bold
count=more
==============
# Building projectName
regexp=^(\[INFO\])( Building )(.*)$
colours=none,bold,none,white bold
count=more
==============
# reactor summary
regexp=([.]{3,} )(SUCCESS)( \[)([^\]]*)(])
colours=none,none,green,none,yellow,none
count=more
==============
# reactor summary
regexp=([.]{3,} )(FAILURE)( \[)([^\]]*)(])
colours=none,none,red,none,red,none
count=more
==============
# reactor summary
regexp=([.]{3,} )(SKIPPED)
colours=none,none,yellow bold,none
count=more

View File

@ -19,7 +19,7 @@ regexp=^IPX.*[\dABCDEF]+:[\dABCDEF]+
colours=green
=======
# protocols
regexp=(^tcp|^udp|^unix|^IPX|STREAM|DGRAM)
regexp=(^tcp6?|^udp6?|^unix|^IPX|STREAM|DGRAM)
colours=bold blue
=======
# status

38
conf.ping2 Normal file
View File

@ -0,0 +1,38 @@
# ip number
regexp=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
colours=magenta
=======
# ipv6 number
regexp=(([0-9a-fA-F]{1,4})?\:\:?[0-9a-fA-F]{1,4})+
colours=magenta
=======
# time
regexp=\d+\.\d+\sms
colours=green
=======
# time
regexp=\d+\sms
colours=green
======
# time
regexp=time=
colours=yellow
=======
# DUP
regexp=DUP\!
colours=red
=======
# (,)
regexp=\(|\)
colours=yellow
=======
# unknown host
regexp=.+unknown\shost\s(.+)
colours=red,bold red
=======
regexp=.*icmp_seq=(\d+) timeout
replace=TIMEOUT \1
colours=red

32
conf.sql Normal file
View File

@ -0,0 +1,32 @@
# this configuration file is for displaying sql scripts very nice to use with sqlformat aka sqlparser
regexp=\w
colours="\033[38;5;140m"
count=more
======
regexp=\b(MIN|MAX|CASE|IF|ELSE|SUBDATE|NOW|ABORT|ABS|ABSOLUTE|ACCESS|ADA|ADD|ADMIN|AFTER|AGGREGATE|ALIAS|ALL|ALLOCATE|ANALYSE|ANALYZE|ANY|ARE|ASC|ASENSITIVE|ASSERTION|ASSIGNMENT|ASYMMETRIC|AT|ATOMIC|AUTHORIZATION|AVG|BACKWARD|BEFORE|BEGIN|BETWEEN|BITVAR|BIT_LENGTH|BOTH|BREADTH|CACHE|CALL|CALLED|CARDINALITY|CASCADE|CASCADED|CAST|CATALOG|CATALOG_NAME|CHAIN|CHARACTERISTICS|CHARACTER_LENGTH|CHARACTER_SET_CATALOG|CHARACTER_SET_NAME|CHARACTER_SET_SCHEMA|CHAR_LENGTH|CHECK|CHECKED|CHECKPOINT|CLASS|CLASS_ORIGIN|CLOB|CLOSE|CLUSTER|COALESCE|COBOL|COLLATE|COLLATION|COLLATION_CATALOG|COLLATION_NAME|COLLATION_SCHEMA|COLLECT|COLUMN|COLUMN_NAME|COMMAND_FUNCTION|COMMAND_FUNCTION_CODE|COMMENT|COMMIT|COMMITTED|COMPLETION|CONDITION_NUMBER|CONNECT|CONNECTION|CONNECTION_NAME|CONSTRAINT|CONSTRAINTS|CONSTRAINT_CATALOG|CONSTRAINT_NAME|CONSTRAINT_SCHEMA|CONSTRUCTOR|CONTAINS|CONTINUE|CONVERSION|CONVERT|COPY|CORRESPONTING|COUNT|CREATEDB|CREATEUSER|CROSS|CUBE|CURRENT|CURRENT_DATE|CURRENT_PATH|CURRENT_ROLE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|CURSOR_NAME|CYCLE|DATA|DATABASE|DATETIME_INTERVAL_CODE|DATETIME_INTERVAL_PRECISION|DAY|DEALLOCATE|DECLARE|DEFAULT|DEFAULTS|DEFERRABLE|DEFERRED|DEFINED|DEFINER|DELIMITER|DELIMITERS|DEREF|DESC|DESCRIBE|DESCRIPTOR|DESTROY|DESTRUCTOR|DETERMINISTIC|DIAGNOSTICS|DICTIONARY|DISCONNECT|DISPATCH|DO|DOMAIN|DYNAMIC|DYNAMIC_FUNCTION|DYNAMIC_FUNCTION_CODE|EACH|ENCODING|ENCRYPTED|END-EXEC|EQUALS|ESCAPE|EVERY|EXCEPT|EXCEPTION|EXCLUDING|EXCLUSIVE|EXEC|EXECUTE|EXISTING|EXISTS|EXTERNAL|EXTRACT|FALSE|FETCH|FINAL|FIRST|FORCE|FOREACH|FOREIGN|FORTRAN|FORWARD|FOUND|FREE|FREEZE|FULL|FUNCTION| 'G|GENERAL|GENERATED|GET|GLOBAL|GO|GOTO|GRANT|GRANTED|GROUPING|HANDLER|HAVING|HIERARCHY|HOLD|HOST|IDENTITY|IGNORE|ILIKE|IMMEDIATE|IMMUTABLE|IMPLEMENTATION|IMPLICIT|INCLUDING|INCREMENT|INDEX|INDITCATOR|INFIX|INHERITS|INITIALIZE|INITIALLY|INOUT|INPUT|INSENSITIVE|INSTANTIABLE|INSTEAD|INTERSECT|INTO|INVOKER|IS|ISNULL|ISOLATION|ITERATE|KEY|KEY_MEMBER|KEY_TYPE|LANCOMPILER|LANGUAGE|LARGE|LAST|LATERAL|LEADING|LENGTH|LESS|LEVEL|LIMIT|LISTEN|LOAD|LOCAL|LOCALTIME|LOCALTIMESTAMP|LOCATION|LOCATOR|LOCK|LOWER|MAP|MATCH|MAXVALUE|MESSAGE_LENGTH|MESSAGE_OCTET_LENGTH|MESSAGE_TEXT|METHOD|MINUTE|MINVALUE|MOD|MODE|MODIFIES|MODIFY|MONTH|MORE|MOVE|MUMPS|NAMES|NATIONAL|NATURAL|NCHAR|NCLOB|NEW|NEXT|NO|NOCREATEDB|NOCREATEUSER|NONE|NOT|NOTHING|NOTIFY|NOTNULL|NULL|NULLABLE|IFNULL|NULLIF|OBJECT|OCTET_LENGTH|OF|OFF|OFFSET|OIDS|OLD|ONLY|OPEN|OPERATION|OPERATOR|OPTION|OPTIONS|ORDINALITY|OUT|OUTPUT|OVERLAPS|OVERLAY|OVERRIDING|OWNER|PAD|PARAMETER|PARAMETERS|PARAMETER_MODE|PARAMATER_NAME|PARAMATER_ORDINAL_POSITION|PARAMETER_SPECIFIC_CATALOG|PARAMETER_SPECIFIC_NAME|PARAMATER_SPECIFIC_SCHEMA|PARTIAL|PASCAL|PENDANT|PLACING|PLI|POSITION|POSTFIX|PRECISION|PREFIX|PREORDER|PREPARE|PRESERVE|PRIMARY|PRIOR|PRIVILEGES|PROCEDURAL|PROCEDURE|PUBLIC|RAISE|READ|READS|RECHECK|RECURSIVE|REF|REFERENCES|REFERENCING|REINDEX|RELATIVE|RENAME|REPEATABLE|RESET|RESTART|RESTRICT|RESULT|RETURN|RETURNED_LENGTH|RETURNED_OCTET_LENGTH|RETURNED_SQLSTATE|RETURNS|REVOKE|RIGHT|ROLE|ROLLBACK|ROLLUP|ROUTINE|ROUTINE_CATALOG|ROUTINE_NAME|ROUTINE_SCHEMA|ROW|ROWS|ROW_COUNT|RULE|SAVE_POINT|SCALE|SCHEMA|SCHEMA_NAME|SCOPE|SCROLL|SEARCH|SECOND|SECURITY|SELF|SENSITIVE|SEQUENCE|SERIALIZABLE|SERVER_NAME|SESSION|SESSION_USER|SETOF|SETS|SHARE|SHOW|SIMILAR|SIMPLE|SIZE|SOME|SOURCE|SPACE|SPECIFIC|SPECIFICTYPE|SPECIFIC_NAME|SQL|SQLCODE|SQLERROR|SQLEXCEPTION|SQLSTATE|SQLWARNING|STABLE|START|STATE|STATEMENT|STATIC|STATISTICS|STDIN|STDOUT|STORAGE|STRICT|STRUCTURE|STYPE|SUBCLASS_ORIGIN|SUBLIST|SUBSTRING|SUM|SYMMETRIC|SYSID|SYSTEM|SYSTEM_USER|TABLE|TABLE_NAME|TEMP|TEMPLATE|TEMPORARY|TERMINATE|THAN|TIMESTAMP|TIMEZONE_HOUR|TIMEZONE_MINUTE|TO|TOAST|TRAILING|TRANSATION|TRANSACTIONS_COMMITTED|TRANSACTIONS_ROLLED_BACK|TRANSATION_ACTIVE|TRANSFORM|TRANSFORMS|TRANSLATE|TRANSLATION|TREAT|TRIGGER|TRIGGER_CATALOG|TRIGGER_NAME|TRIGGER_SCHEMA|TRIM|TRUE|TRUNCATE|TRUSTED|TYPE|UNCOMMITTED|UNDER|UNENCRYPTED|UNION|UNIQUE|UNKNOWN|UNLISTEN|UNNAMED|UNNEST|UNTIL|UPPER|USAGE|USE|USER|USER_DEFINED_TYPE_CATALOG|USER_DEFINED_TYPE_NAME|USER_DEFINED_TYPE_SCHEMA|USING|VACUUM|VALID|VALIDATOR|VALUES|VARIABLE|VERBOSE|VERSION|VIEW|VOLATILE|WHENEVER|WITH|WITHOUT|WORK|WRITE|YEAR|ZONE)\b
colours="\033[38;5;11m"
count=more
======
regexp=\b(ARRAY|BIGINT|BINARY|BIT|BLOB|BOOLEAN|CHAR|CHARACTER|DATE|DEC|DECIMAL|FLOAT|INT|INT8|INTEGER|LONG|NUMBER|NUMERIC|REAL|SERIAL|SERIAL8|SIGNED|SMALLINT|TEXT|TINYINT|UNSIGNED|VARCHAR|VARCHAR2|VARYING)\b
colours=bright_white
count=more
======
regexp=\b(HOUR|MINUTE|SECOND|INTERVAL|SELECT|INSERT|DELETE|UPDATE|REPLACE|MERGE|DROP|CREATE|ALTER|WHERE|FROM|INNER|JOIN|STRAIGHT_JOIN|AND|OR|LIKE|ON|IN|SET|BY|GROUP|ORDER|LEFT|OUTER|FULL|END|THEN|LOOP|AS|FOR|WHILE|WHEN|DISTINCT)\b
colours="\033[38;5;172m"
count=more
======
regexp=\,
colours="\033[38;5;172m"
count=more
======
regexp=\b(\d)\b
colours="\033[38;5;73m"
count=more
======
regexp=[=!><]
colours="\033[38;5;73m"
count=more
======
regexp=\/\*.*?\*\/
colours="\033[38;5;244m"
count=more

7
debian/changelog vendored
View File

@ -1,3 +1,10 @@
grc (1.10-1) unstable; urgency=low
* many configuration files added
* python3 compatible
-- Radovan Garabík <garabik@kassiopeia.juls.savba.sk> Sat, 28 Jan 2017 15:48:58 +0100
grc (1.9-1) unstable; urgency=low
* add `colors' as a synonym of `colours' (and the singulars, too)

4
debian/control vendored
View File

@ -3,11 +3,11 @@ Section: text
Priority: optional
Maintainer: Radovan Garabík <garabik@kassiopeia.juls.savba.sk>
Standards-Version: 3.9.6
Build-Depends: debhelper (>=9)
Build-Depends: debhelper (>=9), python3
Package: grc
Architecture: all
Depends: python, ${misc:Depends}
Depends: ${python3:Depends}, ${misc:Depends}
Description: generic colouriser for everything
generic colouriser, can be used to colourise logfiles,
output of commands, arbitrary text....

6
debian/rules vendored
View File

@ -19,7 +19,8 @@ install:
# Add here commands to install the package into debian/tmp.
./install.sh `pwd`/debian/grc/usr `pwd`/debian/grc
# this is too invasive, would be incluided in a next major version
rm `pwd`/debian/grc/etc/profile.d/grc.bashrc
build: build-arch build-indep
build-arch: build-stamp
@ -47,7 +48,7 @@ binary-indep: build install
dh_installman grc.1 grcat.1
dh_installinfo
# dh_undocumented
dh_installchangelogs
dh_installchangelogs
dh_link
dh_strip
dh_compress
@ -57,6 +58,7 @@ binary-indep: build install
# dh_makeshlibs
dh_installdeb
# dh_perl
dh_python3
dh_shlibdeps
dh_gencontrol
dh_md5sums

View File

@ -1 +0,0 @@
/usr/share/grc/

77
grc
View File

@ -1,13 +1,16 @@
#! /usr/bin/env python
#! /usr/bin/env python3
from __future__ import print_function
import os, re, string, sys, getopt, signal
def version():
print ("Generic Colouriser 1.9.1rc1")
print ("Generic Colouriser 1.10")
sys.exit()
def help():
print("""Generic Colouriser 1.9.1rc1
print("""Generic Colouriser 1.10
grc [options] command [args]
Options:")
-e --stderr redirect stderr. If this option is selected,
@ -15,6 +18,7 @@ Options:")
-s --stdout redirect stdout, even if -e is selected
-c name --config=name use name as configuration file for grcat
--colour=word word is one of: on, off, auto
--pty run command in pseudoterminal (experimental)
""")
sys.exit()
@ -22,14 +26,14 @@ Options:")
def catch_signal(signum, frame):
"catch signal sent to grc and forward it to the original application"
global pidp
# print('signal')
try:
os.kill(pidp, signum)
except OSError: # if the subprocess already died
pass
try:
optlist, args = getopt.getopt(sys.argv[1:], "sec:", ["stdout", "stderr", "config=", "colour="] )
optlist, args = getopt.getopt(sys.argv[1:], "sec:", ["stdout", "stderr", "config=", "colour=", "pty"] )
except:
help()
@ -43,11 +47,14 @@ stderrf = 0
cfile = ""
colour = 1
use_pty = 0
for i in optlist:
if i[0] in ["--stderr", "-e"]:
# redirect stderr
stderrf = 1
elif i[0] in ["--stdout", "-s"]:
# redirect stdout
stdoutf = 1
elif i[0] in ["--config", "-c"]:
cfile = i[1]
@ -60,6 +67,8 @@ for i in optlist:
colour = sys.stdout.isatty()
else:
help()
elif i[0] == '--pty':
use_pty = 1
stdoutff = 1
stderrff = 0
@ -69,14 +78,25 @@ if stderrf == 1:
if stdoutf == 1:
stdoutff = 1
if use_pty:
import pty
conffile = None
if cfile == "":
home = []
if 'HOME' in os.environ:
home = [os.environ['HOME']+"/.grc/grc.conf"]
conffilenames = home + ["/etc/grc.conf"]
home = os.environ.get('HOME')
xdg = os.environ.get('XDG_CONFIG_HOME')
if not xdg and home:
xdg = home + '/.config'
conffilenames = []
if xdg:
conffilenames += [xdg + '/grc/grc.conf']
if home:
conffilenames += [home + '/.grc/grc.conf']
conffilenames += ['/usr/local/etc/grc.conf', '/etc/grc.conf']
for i in conffilenames:
if os.path.isfile(i):
# test if conffile exists, it can be also a pipe
if os.path.exists(i) and not os.path.isdir(i):
conffile = i
break
regexplist = []
@ -102,24 +122,32 @@ if cfile != "" and colour:
choo, chio = os.pipe()
if stderrff:
choe, chie = os.pipe()
pidp = os.fork()
if pidp == 0: # child
if use_pty:
pidp, pty_fd = pty.fork()
else:
pidp = os.fork()
if pidp == 0: # child, command to run
if stdoutff:
os.dup2(chio, 1)
os.close(choo)
os.close(chio)
# connect child (this) stdout to pipe write end
if not use_pty:
os.dup2(chio, 1)
os.close(choo)
os.close(chio)
if stderrff:
os.dup2(chie, 2)
os.close(choe)
os.close(chie)
os.dup2(chie, 2)
os.close(choe)
os.close(chie)
os.execvp(args[0], args)
if stdoutff:
pido = os.fork()
if pido == 0: # child
os.dup2(choo, 0)
if pido == 0: # child, grcat
# connect grcat's stdin to pipe read end, or pty master
if use_pty:
os.dup2(pty_fd, 0)
else:
os.dup2(choo, 0)
os.close(choo)
os.close(chio)
if stderrff:
@ -138,12 +166,15 @@ if cfile != "" and colour:
os.close(choo)
os.close(chio)
os.execvp("grcat", ["grcat", cfile])
try:
status = os.waitpid(pidp, 0)[1]
except OSError: # interrupted system call
status = None
pass # this is probably not correct
# except KeyboardInterrupt: # catching SIGINT does not work when using pty...
# status = None
# os.kill(pidp, signal.SIGINT)
# pass
if stderrff:
os.close(chie)
os.waitpid(pide, 0)
@ -155,7 +186,7 @@ if cfile != "" and colour:
sys.exit(status and os.WEXITSTATUS(status))
else:
pidp = os.fork()
pidp = os.fork()
if pidp == 0:
os.execvp(args[0], args)
try:

View File

@ -1,6 +1,5 @@
GRC=`which grc`
if [ "$TERM" != dumb ] && [ -n "$GRC" ]
then
GRC="$(type -p grc)"
if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then
alias colourify="$GRC -es --colour=auto"
alias blkid='colourify blkid'
alias configure='colourify ./configure'
@ -24,7 +23,8 @@ then
alias lspci='colourify lspci'
alias netstat='colourify netstat'
alias ping='colourify ping'
alias traceroute='colourify /usr/sbin/traceroute'
alias traceroute='colourify traceroute'
alias traceroute6='colourify traceroute6'
alias head='colourify head'
alias tail='colourify tail'
alias dig='colourify dig'
@ -33,4 +33,5 @@ then
alias mtr='colourify mtr'
alias semanage='colourify semanage'
alias getsebool='colourify setsebool'
alias ifconfig='colourify ifconfig'
fi

View File

@ -11,7 +11,7 @@ conf.log
conf.configure
# ping command
(^|[/\w\.]+/)o?ping6?\s
(^|[/\w\.]+/)(io|o)?ping6?\s
conf.ping
# traceroute command
@ -19,7 +19,7 @@ conf.ping
conf.traceroute
# gcc command
(^|[/\w\.]+/)g?cc\s
(^|[/\w\.]+/)(g?cc|[gc]\+\+)\s
conf.gcc
# make command
@ -109,6 +109,10 @@ conf.iproute
(^|[/\w\.]+/)ip n(eighbor)*\s?
conf.ipneighbor
# ip command - rest of commands
(^|[/\w\.]+/)ip?\s
conf.ip
# env
(^|[/\w\.]+/)env\s?
conf.env
@ -141,8 +145,11 @@ conf.iostat_sar
(^|[/\w\.]+/)free\s?
conf.free
# docker -----------------------------
(^|[/\w\.]+/)docker ps\s?
------------
# docker
# docker ps
(^|[/\w\.]+/)docker(-compose)? ps\s?
conf.dockerps
(^|[/\w\.]+/)docker images\s?
@ -165,6 +172,7 @@ conf.dockerinfo
(^|[/\w\.]+/)docker version\s?
conf.dockerversion
------------
# journalctl command
(^|[/\w\.]+/)journalctl?\s
@ -229,3 +237,12 @@ conf.getfacl
# showmount
(^|[/\w\.]+/)showmount\s?
conf.showmount
# apache ant command
(^|[/\w\.]+/)ant\s?
conf.ant
# # apache maven command
(^|[/\w\.]+/)mvn\s?
conf.mvn

41
grcat
View File

@ -1,4 +1,6 @@
#! /usr/bin/env python
#! /usr/bin/env python3
from __future__ import print_function
import sys, os, string, re, signal, errno
@ -84,16 +86,30 @@ def get_colour(x):
home = []
conffile = None
if 'HOME' in os.environ:
home = [os.environ['HOME']+"/.grc/"]
conffilepath = [""] + home + ["/usr/local/share/grc/", "/usr/share/grc/"]
xdg_config = os.environ.get('XDG_CONFIG_HOME')
xdg_data = os.environ.get('XDG_DATA_HOME')
home = os.environ.get('HOME')
if home and not xdg_config:
xdg_config = home + '/.config'
if home and not xdg_data:
xdg_data = home + '/.local/share'
conffilepath = [""]
if xdg_data:
conffilepath += [xdg_data + '/grc/']
if xdg_config:
conffilepath += [xdg_config + '/grc/']
if home:
conffilepath += [home + '/.grc/']
conffilepath += ['/usr/local/share/grc/', '/usr/share/grc/']
if len(sys.argv) != 2:
sys.stderr.write("You are not supposed to call grcat directly, but the usage is: grcat conffile\n")
sys.exit(1)
conffile_arg = sys.argv[1] # tentative conffile
for i in conffilepath:
if os.path.isfile(i+conffile_arg):
# test if conffile exists, it can be also a pipe
if os.path.exists(i+conffile_arg) and not os.path.isdir(i+conffile_arg):
conffile = i+conffile_arg
break
@ -130,7 +146,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
@ -147,16 +163,12 @@ while not is_last:
# do not try to understand the optimized form below :-)
if 'colours' in ll:
colstrings = list(
map(
lambda colgroup:
''.join(map(lambda x: get_colour(x), split(colgroup))),
split(ll['colours'], ',')
)
[''.join([get_colour(x) for x in split(colgroup)]) for colgroup in split(ll['colours'], ',')]
)
ll['colours'] = colstrings
cs = ll['count']
if ll.has_key('regexp'):
if 'regexp' in ll:
ll['regexp'] = re.compile(ll['regexp']).search
regexplist.append(ll)
@ -210,6 +222,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:

View File

@ -25,6 +25,7 @@ where keyword is one of:
.BR regexp ",
.BR colours ",
.BR command ",
.BR concat ",
.BR skip ",
.BR count ".
Only