garabik / grc Goto Github PK
View Code? Open in Web Editor NEWgeneric colouriser
Home Page: http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
License: Other
generic colouriser
Home Page: http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
License: Other
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
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:
df
header line.ifconfig
docker
support: ps
, info
, images
, docker-machine
.journalctl
supportTime for a new release? :)
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)
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
Is there a reason why grc.zsh
and grc.fish
are not included in the install.sh
script? Further it seams that not all executable are included in these integrations e.g. uptime is missing in grc.zsh
but also in the grc plugin from oh-my-fish.
Maybe relevant:
https://github.com/Homebrew/homebrew-core/blob/master/Formula/grc.rb
https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/grc
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:
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).
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.
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:
I want the file names to be colorized rather than the file permissions (or both), i. e.:
grc
also kind of messes up ls -F
:
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
)
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
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.
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
.
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
Hi
You fixed the double findmnt in the dev version of grc
But, findmnt is always twice in master version.
Is there a reason ?
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?
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.
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
stringcat log/1.log |./grcat conf.my_log |less -r
/Warning
Warning
disappearAm I the only one to encounter this issue ?
It would be nice to have a one-line installer without having to git clone
(like there's brew install grc
on OS X).
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.
Is there a reason that more commands are aliased in:
https://github.com/garabik/grc/blob/master/grc.bashrc
than in:
/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?
The ls command is being aliased in grc.bashrc
using:
alias ls='colourify ls --color'
Which results in:
$ ls
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
ls
in osx does not accept the --color
option. In fact, I don't think it accepts any double minus options. The correct options is -G
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/ls.1.html
grc.fish
breaks a lot of commands when using in interactive fish shell, such as grep
and systemctl
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: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?
Hi
Could grc be installed without root permission in my home folder?
I have a server but I am not a sudoer.
Thanks :)
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.
I would expect it to colourise each timeout char as soon as it happens, instead of buffering the whole line.
Any chance of getting support for pv
?
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.
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
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?
(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.
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)
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.
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 *
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?
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
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.
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)
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 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.
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
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:
grc
into ~/.bashrc
brew install grc
, then add the following to ~/.bashrc
: source "$(brew --prefix)/etc/grc.bashrc"
bash
shell & cd to the directory with this Makefile
make test
read
(as the Makefile
is written to do)read
was actually expecting input, which you were unaware ofThen, 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)
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.
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):
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.