Git Product home page Git Product logo

grc's Introduction

Generic Colouriser

Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/software/grc.html (garabik @ kassiopeia.juls.savba.sk)

For the impatient - try following commands:

grc netstat
grc ping hostname
grc tail /var/log/syslog
grc ps aux

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.

Two programs are provided: grc and grcat. The main is grcat, which acts as a filter, i.e. taking standard input, colourising it and writing to standard output.

Configuration

grcat takes as a parameter the name of configuration file.

Directories ~/.grc/, /usr/local/share/grc/, /usr/share/grc/ are searched for the file (in this order). If the file is not found, it is assumed to be an absolute path of a configuration file located elsewhere.

Configuration file consists of entries, one per regexp, entries are separated with lines with first character non-alphanumeric (except #). Lines beginning with # or empty lines are ignored.

Each entry consists of several lines.

Each line has form: keyword=value

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.

regexp is the regular expression to match.

colours is the list of colours, separated by commas (you can specify only one colour), each colour per one regexp group specified in regexp.

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

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

Yet another special name is an arbitrary string enclosed in straight quotes. This string will be inserted directly into the output in front of the matching expression. The string will be eval'ed, so you can use usual python escape sequences.

This is useful on a 256-colour enabled xterm, where e.g. colours="\033[38;5;22m" will give you a dark green (inspired by Rutger Ovidius). Caveat: the string cannot contain a comma. This is due to my laziness :-)

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.

all the following regular expressions will be evaluated against the replaced text, not the original.

replacement is done by re.sub(), therefore you can use anything python supports - in particular, \1, \2 etc... to include text from the original matching groups, e.g:

regexp=(\d\d):(\d\d):(\d\d)
replace=\1h\2m\3s

will change time format from 09:43:59 into 09h43m59s

count is one of words: once, more, stop, previous, block or unblock

  • once means that if the regexp is matched, its first occurrence is coloured and the program will continue with other regexp's.
  • more means that if there are multiple matches of the regexp in one line, all of them will be coloured.
  • stop means that the regexp will be coloured and program will move to the next line (i.e. ignoring other regexp's)
  • previous means the count will be the same as for the previous line
  • block marks a start of a multiline block of text, coloured with the same colour
  • unblock, obviously, marks the end of such a block

example:

# this is probably a pathname
regexp=/[\w/\.]+
colour=green
count=more

this will match /usr/bin, /usr/local/bin/, /etc/init.d/syslogd and similar strings and paint it with green.

Another example:

regexp=^-{1,2}\s{0,1}$
colours=red
count=block
-
regexp=^\s{0,5}$
colours=default
count=unblock

this will turn all correctly formatted mail signatures red.

Regular expressions are evaluated from top to bottom, this allows nested and overlapped expressions. (e.g. you colour everything inside parentheses with one colour, and if a following expression matches the text inside parentheses, it will be also coloured).

Typical usage:

grcat conf.log < /var/log/syslog
/usr/sbin/traceroute www.linux.org | grcat conf.traceroute
grcat conf.esperanto < Fundamento.txt  | less -r

To facilitate the use, command grc acts as frontend for grcat, automatically choosing the configuration files, so you can write:

grc netstat
grc ping hostname
grc tail /var/log/syslog

etc...

grc will execute command command with optional parameters piping its stdout into grcat.

Configuration file for grcat is determined by /etc/grc.conf or ~/.grc/grc.conf file.

Format of /etc/grc.conf or ~/.grc/grc.conf: each entry consists of 2 lines, between entries there can be any number of empty lines or lines beginning with # (comments).

First line is regular expression, second line the name of configuration file for grcat.

Configuration file after the first regular expression matching the rest of line after grc will be passed to grcat as its configuration file

For example, if you have

# log file
\b\w+\b.*log\b
conf.log

# traceroute command
(^|[/\w\.]+/)traceroute\s
conf.traceroute

in your /etc/grc.conf, then typing grc cat /var/log/syslog will use conf.log to colourise the output, grc /usr/sbin/traceroute www.linux.org will use conf.traceroute.

Miscellaneous remarks:

You should get yourself familiar with regular expressions. Good reading is at http://docs.python.org/dev/howto/regex.html

The program is not yet optimized for speed. There are places that can give a big boost if optimized.

Regular expressions are handled by python, it means that they may be slightly different from those you know from perl or grep. It's not my fault in that case.

Colours are one of:

none, default, bold, underline, blink, reverse, concealed,
black, green, yellow, blue, magenta, cyan, white,
on_black, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white
beep

on_red means that the background (instead of foreground) is painted with red etc...

Additional colours can be: dark, italic, rapidblink, strikethrough. These are supported only on some terminals, so if you want to write portable configuration files, avoid uing them (idea by James Rowe).

there can be more attributes per line (separated by space), e.g.

# this is probably a pathname
regexp=/[\w/\.]+
colours=bold blink green
count=more

will display pathnames in bold blinking green

Python 2 & 3 compatibility

both grc and grcat are targetted towards python3 now; there is an attempt at python2 compatibility, meaning that both grc and grcat will run under both python2 and python3. However, all the regular expressions are strings, and grcat works on string input (not bytes).

Hints

Following commands will display nice coloured log in virtual console 12:

If you have GNU tail:

tail --follow=name /var/log/syslog | grcat conf.log >/dev/tty12

or, if you have recent BSD tail:

tail -F /var/log/syslog | grcat conf.log >/dev/tty12

Automatic aliases

You can start using grc automatically with supported commands. The following assumes that grc.<sh|zsh|fish> is in /etc. The location may differ (i. e. /usr/local/etc when installed with homebrew); or the grc.sh can be placed into /etc/profile.d/ (this is in fact the default). Be aware this is somewhat invasive and better test it before deploying.

Bash

To set aliases for supported commands, append to your ~/.bashrc:

GRC_ALIASES=true
[[ -s "/etc/profile.d/grc.sh" ]] && source /etc/grc.sh

If the file /etc/default/grc exists, it is sourced first, therefore you can place a line saying GRC_ALIASES=true there.

ZSH

Or for zsh users, append to ~/.zshrc:

[[ -s "/etc/grc.zsh" ]] && source /etc/grc.zsh

Fish

Add to ~/.config/fish/config.fish or in a new file in ~/.config/fish/conf.d/:

source /usr/local/etc/grc.fish

Dynamic aliases

By running the follow code, it will check to see what programs are already installed on your OS (based on your $PATH), and echo out the result. This could then be added to your shell resource file as a one off. Alternatively, by removing the echo in the code, it could be placed into your shell resource file directly, and it will create the necessarily aliases each time:

for cmd in g++ gas head make ld ping6 tail traceroute6 $( ls /usr/share/grc/ ); do
  cmd="${cmd##*conf.}"
  type "${cmd}" >/dev/null 2>&1 && echo alias "${cmd}"="$( which grc ) --colour=auto ${cmd}"
done

grc's People

Contributors

alcik avatar bladeroot avatar codydiehl avatar darkain avatar derimagia avatar exzz avatar feriman avatar franga2000 avatar g0tmi1k avatar garabik avatar grassharper avatar hjpotter92 avatar iax7 avatar jlec avatar jnovack avatar joeky888 avatar jooray avatar junkdog avatar kapsh avatar lbschenkel avatar luisdavim avatar matthiaswinkelmann avatar mzhukov-dlink avatar nosuck avatar raizo62 avatar rpolishchuk avatar sasq64 avatar tasnad avatar wwalker avatar xpmo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grc's Issues

How can I install grc on Mac OS?

Hello,

is there any package for Max OS?
At best in version 1.9 ;)

I have found packages for e.g. Debian, but not for Mac OS. I would like to provide an installation guide for Mac OS users, so they can experience the same features as Linux users.

Update:
I found a brew formula for Grc, but it has no version info or other description. There is only a link to the grc website. Can it be updated?

Related pull requests: #32

Update 2:
According to an answer to issue #32, brew will install version 1.9.

Thanks
Patrick

Process substitution does not work because of "isfile" check

Hi, it may be useful to use grc without a configuration file, e.g. in oneliners.

However, piping through

... | grcat <(echo regexp=.*2015.*; echo colours=red)

fails, because "isfile" check returns False in such a case.

The fix is simple, just replace line:

if os.path.isfile(i+conffile_arg):

with:

if os.path.exists(i+conffile_arg) and not os.path.isdir(i+conffile_arg):

Install grc without sudo

Hi

Could grc be installed without root permission in my home folder?

I have a server but I am not a sudoer.

Thanks :)

the tty's size is ignored

It's very obvious when running ps aux that the tty's size is ignored by grc. Cope doesn't seem to have this problem. I'm guessing that is emulates a tty?

grc upgraded from 1.9 to 1.10_1 fails with argument errors

I recently did a brew upgrade on my Mac of grc, and I am now seeing the following errors after every command:

ls: --colour=auto: No such file or directory
ls: -es: No such file or directory
ls: -f: No such file or directory
ls: env: No such file or directory
ls: is: No such file or directory
ls: mv: No such file or directory
-rw-r--r-- 1 i831533 staff 17K Feb 9 12:21 /Users/butch/.z
-rw-r--r-- 1 i831533 staff 17K Feb 9 12:22 /Users/butch/.z.26293
lrwxr-xr-x 1 i831533 admin 28B Feb 9 12:21 /usr/local/bin/grc@ -> ../Cellar/grc/1.10_1/bin/grc
ls: --colour=auto: No such file or directory
ls: -es: No such file or directory
ls: -f: No such file or directory
ls: env: No such file or directory
ls: is: No such file or directory
ls: rm: No such file or directory
-rw-r--r-- 1 i831533 staff 17K Feb 9 12:22 /Users/butch/.z.26293
lrwxr-xr-x 1 i831533 admin 28B Feb 9 12:21 /usr/local/bin/grc@ -> ../Cellar/grc/1.10_1/bin/grc

Also note that after every command, a new file of the form ".z." is created in my home directory, presumably to provide a temporary location from which to colorize output.

Rolling back to grc 1.9 makes the problem go away.

Perhaps this is a duplicate of issue #50?

progressively coloring character instead of line output

When a command progressively sends characters to stdout on the same line, grc waits for the whole line, applies color and eventually returns the output.
Here's an example with traceroute on OS X.

2-1
2-2

I would expect it to colourise each timeout char as soon as it happens, instead of buffering the whole line.

1-1
1-2
1-3

Use default conf if no conf given

If you call grcat without configuration for a filetype, you should give out a warning that a default.conf is used.

this default.conf should colourize most typical scructures in all different types of codes.

the hint should link to an explanation where to get configuration examples for the most common programming languages

missing newline at end of configuration breaks last colour

grc 1.11.1, installed via macOS homebrew.

I copied conf.tcpdump and added this to it:

-
# DNS queries
regexp=((A|AAAA)\? [^ ]+)
colours=green

This works, but only if there is a newline after green. When I remove the newline, this happens:

Traceback (most recent call last):
  File "/usr/local/bin/grcat", line 166, in <module>
    [''.join([get_colour(x) for x in split(colgroup)]) for colgroup in split(ll['colours'], ',')]
  File "/usr/local/bin/grcat", line 166, in <listcomp>
    [''.join([get_colour(x) for x in split(colgroup)]) for colgroup in split(ll['colours'], ',')]
  File "/usr/local/bin/grcat", line 166, in <listcomp>
    [''.join([get_colour(x) for x in split(colgroup)]) for colgroup in split(ll['colours'], ',')]
  File "/usr/local/bin/grcat", line 84, in get_colour
    raise ValueError('Bad colour specified: '+x)
ValueError: Bad colour specified: gree

The error appears to be on line 138 of grcat, which assumes there is always a trailing character to remove:

        fields = split(l[:-1], "=", 1)

Changing that line to

        fields = split(l.strip(), "=", 1)

makes it work for me, but I'm unsure if stripping is always legal while parsing grc configs.

Incorrect "Permission denied" on non-existent command

If grc tries to run a non-existent command, it says Permission denied:

% grc --colour=auto fdsfasd
grc: fdsfasd: Permission denied

I'd expect it to do say something like the shell (first is zsh):

% fdsfasf
zsh: command not found: fdsfasf
% exec bash
$ fdasfasd
bash: fdasfasd: command not found

So I suggest the desired behaviour is:

grc: fdsfasd: command not found

Time for a new release?

I love using grc, makes my day a little brighter, but I noticed the last release were almost a year (or 27 commits) ago. Many new features have been added:

  • Colorization of df header line.
  • IPv6 support for ifconfig
  • docker support: ps, info, images, docker-machine.
  • journalctl support

Time for a new release? :)

Support more colors

As far as I know, the only colors that are supported are:

black, green, yellow, blue, magenta, cyan, white

Is it possible to support a wider spectrum of colors? 256 colors would be great.

Automatic aliases error (invalid integer '501')

OS: macOS 10.12.5 (Sierra)
Homebrew 1.2.2
FishShell: 2.6.0
iTerm: 3.0.15 (with shell integration)

After adding source /usr/local/etc/grc.fish to ~/.config/fish/config.fish upon new shell, or any other new command i get this:

test returned eval errors:
	invalid integer '501'

grc df; missing lines in output

When running df through grc there are lines missing from the output. When running df normally it looks like this:
df

But when running grc df it is missing the tmpfs lines, like this:
grc df

And when i highlight the text, it looks like this:
grc df marked

Weird right?

grc.zsh overrwrites existing aliases

Trying to use grc.zsh to integrate with zsh, it overwrites any existing aliases for the commands being colorized.

e.g. if I had

alias ls='ls -ltr'

set already, then sourcing grc.zsh overwrites my ls alias.
I think most people would put the colorizing at the end of their .zshrc, so this could be avoided by setting the alias to the value of an existing alias, if one exists.

The line that does it is here:
https://github.com/garabik/grc/blob/master/grc.zsh#L34

alias $cmd="grc --colour=auto $cmd"

If you could pass in the current value of the alias if one exists, it'd avoid this issue.

Line disappear when use search in less

Hi,

I use "less" command with grcat but when I make a search on pattern that are in grcat configuration the line that contain a match disappears.

To reproduce:

  • conf.my_log
regexp=Critical
colours=red
======
regexp=Warning
colours=yellow
  • log/1.log contain lot of Warning string
  • cat log/1.log |./grcat conf.my_log |less -r
  • Then search in less /Warning
  • The first line that contain Warning disappear

Am I the only one to encounter this issue ?

Option to verify that given command is supported by grc rules

I'm looking for way to automatically alias all commands that supported by given grc configuration. Right now my approach is dumb, it verifies if there is conf.${command} file present and aliases this command. But as grc.conf defines regexp that could match multiple commands, my approach is suboptimal.

What I'd like to have is an option to check, if given command is supported by current grc configuration.

colourify alias is messed up

After installing fresh with Homebrew on MacOS, /usr/local/etc/grc.bashrc seems to set a very weird alias for colourify.

Instead of it being alias colourify='grc -es --colour=auto', it ends up being executed as alias 'colourify=grc is /usr/local/bin/grc -es --colour=auto', which as you can imagine threw some pretty big errors whenever I tried my ls command, or any other command relying on colourify.

My solution was to manually use grc instead of the $GRC generated at the top of the grc.bashrc file.

pip3 install error: ImportError: No module named 'error'

Installed grc with pip3 --user (python 3.5.2) on Ubuntu 16.04, getting this error:

Traceback (most recent call last):
  File "/home/antho/.local/bin/grc", line 19, in <module>
    from grc.yaml import load
  File "/home/antho/.local/lib/python3.5/site-packages/grc/yaml/__init__.py", line 2, in <module>
    from error import *
ImportError: No module named 'error'

__init__.py calls error.py in the same directory

head /home/antho/.local/lib/python3.5/site-packages/grc/yaml/__init__.py

from error import *

Python2 compatibility

Hi, I maintain the FreeBSD port of grc and I'm busy updating our package to v1.11.

I noticed that the README states that grc has python2 + python3 compatibility.

The python3 in the shebang is not a problem, we replace that with the python interpreter of the user's choosing.

However, in commit 1516a3e the python3-only FileNotFoundError was introduced. This gives the following error on python2:

# grc foo
Traceback (most recent call last):
  File "/usr/local/bin/grc", line 193, in <module>
    except FileNotFoundError:
NameError: name 'FileNotFoundError' is not defined

Besides the try-except part, grc seems to still run fine on python2 otherwise.

I would like not forcing users to install python3, so I would prefer to change the try-except in grc to something like this, which would work in python2/3 and still be mostly informative I think:

        try:
            os.execvp(args[0], args)
        except OSError:
            sys.stderr.write('grc: %s: command not found\n' % args[0])
            sys.exit(1)
        except Exception as e:
            sys.stderr.write('grc: %s: %s\n' % (args[0], e.strerror))
            sys.exit(1)

Other solutions would be welcome too.

Alternatively, if grc will support python3 only, this doesn't need to be changed (but the README would); in that case I might either patch it downstream for python2 users or I would just require python3 as a dependency.

findmnt in grc.conf in master

Hi

You fixed the double findmnt in the dev version of grc

But, findmnt is always twice in master version.

Is there a reason ?

(grcat) exit code zero despite previous pipe command returning non-zero

(I know grcat isn't meant for public use but like i said in another ticket it's really convenient; if this is unsupported I'm just putting this ticket out there in case grcat becomes supported)

When I run:

mvn compile | grcat ~/conf.mvn

and the compilation fails, I get exit code zero. This makes it a bit difficult to run a script that checks whether the compilation succeeded before running the next command. For example, I often run this:

mvn compile | grcat ~/conf.mvn && sh deploy_my_app.sh

and when deploy_my_app.sh prints loads of stuff and I'm not looking at my screen I don't see the failed mvn command, so start tearing my hair out wondering my my app isn't working.

grcat colourize stderr?

Does grcat support colourizing stderr? If not, can it be added (possibly with the ability to specify a different conf file)?

I know grc has the --stderr option to (presumably) colourize stderr but I like to use grcat since it works nicely with pipes and thus is more Unix-philosophy-friendly than grc.

My redirection efforts so far have been unsuccessful:

(>&2 echo "INFO error") | grcat ~/conf.tail 2>(grcat ~/conf.tail)

How to setup GRC in a MinGW environment?

I like GRC, so I use it for many of my Linux tools to add some colors. I would like to get the same coloring in my MinGW environments:

  • Git Bash of Git for Windows
  • MinGW32
  • MinGW64

I saw, the core of GRC is Python. So the question is where to put what files, right?

There is a PyPI entry for GRC, but it is absolutely outdated (1.0b4).

zsh ls -l colours permissions instead of files

image

I want the file names to be colorized rather than the file permissions (or both), i. e.:

image

grc also kind of messes up ls -F:

image

At the moment I'm just reseting alias ls='/bin/ls' after adding the grc aliases, but i don't get why grc would apply that kind of coloring? Or is there something wrong with my zsh config? (I use CLICOLOR=true)

grc not working with less +F

grc -c my.conf less -F some.log does not work as expected. The output is shown until the end of the file and not waiting for new lines to be added. This should work/behave the same way as grc -c my.conf tail -f some.log.

GNU make: grc causes shell builtin `read -p "prompt text: "` to not print to terminal in Makefile

When using the read -r -p "some prompt here: " bash builtin and having grc loaded into the shell, it appears that the prompt is never displayed. This can cause confusion with things that spawn sub-shells such as make, and probably some bash scripts (maybe other tools too).

Here is a Makefile to reproduce the issue

To reproduce:

  1. Install & load grc into ~/.bashrc
  • For example: brew install grc , then add the following to ~/.bashrc: source "$(brew --prefix)/etc/grc.bashrc"
  1. Spawn a bash shell & cd to the directory with this Makefile
  2. Run make test
  3. Watch as you are not prompted by read (as the Makefile is written to do)
  4. Press enter and see that read was actually expecting input, which you were unaware of
  5. Try again, this time typing something and hitting enter... now it shows you it did read some input and set a variable.

Then, try commenting out the source line which loads grc into the shell. Retry the same make test and see the prompt is shown.

I'm stumped as to why loading grc is affecting shell builtins in this way... the entire contents of the file under $(brew --prefix)/etc/grc.bashrc only has alias definitions:

GRC=`which grc`
if [ "$TERM" != dumb ] && [ -n "$GRC" ]
then
    alias colourify="$GRC -es --colour=auto"
    alias configure='colourify ./configure'
    alias diff='colourify diff'
    alias make='colourify make'
    alias gcc='colourify gcc'
    alias g++='colourify g++'
    alias as='colourify as'
    alias gas='colourify gas'
    alias ld='colourify ld'
    alias netstat='colourify netstat'
    alias ping='colourify ping'
    alias traceroute='colourify /usr/sbin/traceroute'
    alias head='colourify head'
    alias tail='colourify tail'
    alias dig='colourify dig'
    alias mount='colourify mount'
    alias ps='colourify ps'
    alias mtr='colourify mtr'
    alias df='colourify df'
fi

I've tested this with:

bash --version = GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin15.6.0)
make --version = GNU Make 3.81
grc --version = Generic Colouriser 1.11.1 (from Homebrew)

And it also appears to affect the default shell /bin/sh on mac as well:

/bin/sh
sh-3.2$ source "`brew --prefix`/etc/grc.bashrc"
sh-3.2$ make test

You must specify SOME_ENV_VAR or set env variable SOME_ENV_VAR !
Enter SOME_ENV_VAR (eg 'bar') (set environment variable SOME_ENV_VAR to skip this prompt): make: *** [test] Error 1

/bin/sh --version = GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
make --version = GNU Make 3.81
grc --version = Generic Colouriser 1.11.1 (from Homebrew)

using grc with javac produces error

/etc/grc.conf

# javac
(^|[/\w\.]+/)javac\s?
conf.javac

/usr/share/grc/conf.javac

# warning
regexp=warning
colour=yellow
=======
# error
regexp=error
colour=red
=======

Result

[ra@archnb AESKeyLock]$ grc javac
Traceback (most recent call last):
  File "/usr/bin/grcat", line 152, in <module>
    ll['regexp'] = re.compile(ll['regexp']).search
KeyError: 'regexp'
Usage: javac <options> <source files>
...

I'm not completely sure this isn't some kind of user error, but I don't know how to fix it myself?

streaming/buffering issue

If you run netstat you'll see that grc seems to not stream output as it comes in. Cope handles this better. Maybe it does line based buffering while grc uses some other strategy? I haven't looked at the code, so I don't know what's causing this.

Error when installing the deb package on Ubunto 14.04 LTS

I get this error on Ubuntu 14.04 LTS (this is the sudo enabled version of Ubuntu on Travis-CI).

subprocess dpkg-deb --control returned error exit status 2

Any ideas what causes this error and how to solve it?

Here is the full error log:

Downloading grc.deb from https://korpus.sk/~garabik/software/grc/grc_1.11.3-1_all.deb...
Download [SUCCESSFUL]
Installing grc.deb... 
dpkg-deb: error: archive 'grc.deb' has premature member 'control.tar.xz' before 'control.tar.gz', giving up
dpkg: error processing archive grc.deb (--install):
 subprocess dpkg-deb --control returned error exit status 2
Errors were encountered while processing:
 grc.deb
Installation [FAILED]

This is my download/install/setup script:

# install grcat
if [ -e $GRC_DEB ]; then
  echo -e "${CYAN}Installing $GRC_DEB... ${NOCOLOR}"
  sudo dpkg -i $GRC_DEB
  if [ $? -eq 0 ]; then
    echo -e "${GREEN}Installation [SUCCESSFUL]${NOCOLOR}"
  else
    echo 1>&2 -e "${RED}Installation [FAILED]${NOCOLOR}"
    exit 1
  fi
fi

Full Sources: https://github.com/VLSI-EDA/PoC/blob/master/tools/Travis-CI/grc.setup.sh?ts=2


Related issues:

grc du -hs ~/.cache/*

I'm using grc version 1.11.1. The command in the title is not working properly - for some reason the following in grc.conf is matched:

# log file
\b\w+\b.*log\b
conf.log

Instead of the settings for du. For all other directories other than .cache the du command is being colorized fine.

findmnt in grc.conf

Hi

I believe that the configuration of findmnt is twice in "/etc/grc.conf"
first : line 65 :

65 # findmnt command 
66 (^|[/\w\.]+/)findmnt\s? 
67 conf.findmnt 

second : line 164

164 # findmnt 
165 (^|[/\w\.]+/)findmnt\s? 
166 conf.findmnt 

I think that is not useful

ifconfig freeze with empty flags

If ifconfig returns empty flags list (BSD systems do this), grc(at) freezes (or rather consumes 100% CPU):

echo '<>' | grcat /usr/local/share/grc/conf.ifconfig

grcat hangs when using replace

I have a log file in which I would like to replace , with \n, .

So, I put the following in a configuration file my.config:

regexp=(,)
replace=\n,

and call it like grcat my.config < some_logifle.

But this only results in high cpu load and grcat does not respond. I have to kill the process by force.

This also happens with things like:

regexp=,
replace=\n,

or:

regexp=(,)
replace=\1\n

or simply:

regexp=(,)
replace=\1

This works, though:

regexp=(,)
replace=\n

python --version gives me:
Python 2.7.15

error colorizing python code

grcat $(which grc)

results in:

Traceback (most recent call last):
  File "/usr/bin/grcat", line 98, in <module>
    keyword, value = split(l[:-1], "=", 1)
ValueError: need more than 1 value to unpack

grc possibly breaks zsh completion

grc:v1.11.3
zsh:5.5.1-1
OS:Arch linux

I have a rather strange issue.Commands aliased with grc are not completed by zsh when i have
setopt NO_COMPLETE_ALIASES set, but aliases set by me work normal.
For instance
alias pacrem='sudo pacman -Rns'
is getting pacman completions, while
grc --colour=auto /usr/bin/blkid is broken.
If i set setopt COMPLETE_ALIASES the inverse happens and all my normal aliases stop working while i get completions from grc ones.
Any ideas on how to fix that?

PyPI submission

It would be nice to have a one-line installer without having to git clone (like there's brew install grc on OS X).

after running mtr, my terminal size changes

Actual command ran is /usr/bin/grc -es --colour=auto mtr github.com, which is an alias of mtr after an update.

It runs mtr in a somewhat 80x24 sized space instead of what my terminal actually is, and after I exit, there are some strange things like when the cursor is at the last line, it doesn't scroll (only the last line updates), after Ctrl-L, my cursor can't go down after 24 lines or so (it scrolls).

After running reset, vim or htop, it restores to normal.

I'm on Arch Linux and grc is of version 1.11.1-2.

Color files as plugins

I haven't checked it this can be done easily with the current code, but i'm thinking about that instead to need a separate file to check the regex to the configured commands, to have a dedicated directory like
~/.grc.d containing all the configuration files, and them contains the command regex. Something like this:

command=(^|[/\w\.]+/)dig\s?
=======
#ipv6
regexp=(([0-9a-fA-F]{1,4})?\:\:?[0-9a-fA-F]{1,4})+
colours=green
=======
...

In this way we colour configuration files could be easily detached from this project, and additional files can be added independently like a plugin system from other github's repos.

conf.sh / conf.bash - for shell scripts

I couldn't find a conf file for shell scripts. If one doesn't exist, could we create one? I sometimes like to do this:

cat run.sh | grcat ~/conf.sh

(I know grcat shouldn't be used directly but it is Unix idiomatic so very convenient to stick onto the end of whatever you were doing)

Colours for ls grc.zsh

The alias for ls not ideal because it results in ls not using the original colouring, e.g. executables are green and directories are blue.

The following alias will keep the standard ls colour in addition to the grc colouring:

 alias ls='grc --colour=auto ls --color=always'

Note that the colour parameter must be set to always, as setting it to auto won't work with grc.

"FileNotFoundError: [Errno 2] No such file or directory" in version 1.10_1

I just installed the latest version from Homebrew, then sourced "$(brew --prefix)/etc/grc.bashrc". I'm using zsh 5.3.1 When I run ls (or anything else that grc would colorize), I get this:

Traceback (most recent call last):
  File "/usr/local/Cellar/grc/1.10_1/libexec/bin/grc", line 191, in <module>
    os.execvp(args[0], args)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 559, in execvp
    _execvpe(file, args)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 604, in _execvpe
    raise last_exc.with_traceback(tb)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 594, in _execvpe
    exec_func(fullname, *argrest)
FileNotFoundError: [Errno 2] No such file or directory

All my Homebrew logs are here: https://gist.github.com/slhck/bd7416f37c61745c1c787c209d0c1e52

Running grc itself works (although the ") after Options: seems weird…):

Generic Colouriser 1.10
grc [options] command [args]
Options:")
-e --stderr    redirect stderr. If this option is selected,
               do not automatically redirect stdout
-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)

I can also disable grc by not sourcing the .bashrc file and then run it manually without problems:

$ grc -es --colour=auto ls
foo
bar

Any pointers?

non capturing group

quite sure i'm overlooking some piece of readme and example, but i cant find how to color just a part of regexp match.
for example, i have a line like:

foo:pub;let's have a drink at the pub

and i want to have just the first "pub" coloured.

i'd do:
regexp=(?::)(\w+)(?:;)
color=green

but no green string on my terminal.
did i get this wrong?

grcat graceful exit without args

Running grcat with no args gave me a python error.

Traceback (most recent call last):
File "/usr/bin/grcat", line 90, in
conffile_arg = sys.argv[1] # tentative conffile
IndexError: list index out of range

I patched it to not crash by adding these lines at grcat:90

if len(sys.argv) == 1:
sys.stderr.write("config file not found\n")
sys.exit(1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.