Colout – add colors to a text stream in your terminal(nojhan.github.io) |
Colout – add colors to a text stream in your terminal(nojhan.github.io) |
Grcat lets you configure commands with colour regexps. Then you just prefix the command with "grc", and it will colorize the output according the rules. It's useful to alias commands this way:
$ alias make="grc make"
colout seems most useful when you are want to highlight arbitrary patterns independent of the command, eg. "tail some.log | colout ...".[1] http://kassiopeia.juls.savba.sk/~garabik/software/grc/README...
Plus, colout have a tons of additional features (256-colors mode, colormaps, etc.).
regexp=^\+(.*$)
colours=bold green
count=more
=======
regexp=^\-(--.+$|[^\-].*$|$)
colours=bold red
count=more
========
regexp=^\>([^\>].*|$)
colours=bold green
count=more
=======
regexp=^\<([^\<].*|$)
colours=bold red
count=more
=======
regexp=^@@ .* @@$
colours=magenta
count=more
I agree that colout works better for ad-hoc stuff.You should consider inverting the way it's invoked, though, to be more like grc, otherwise you can't reliably use colout in an alias (as pointed out elsewhere in this thread).
The website says:
colout -r will give you the lists of available colors,
colormaps, themes and supported programming languages.
But I think that's a typo and should be 'colout -h'.Also, a handy alias list of common use cases would be great.
Alias for common use cases are named "themes" in the list of resources.
% colout -r
usage: colout.py [-h] [-g] [-c] [-l SCALE] [-a] [-t] [-s]
REGEX [COLOR] [STYLE]
colout.py: error: too few argumentsI can see a bunch of ways I'll make use of this. The first one I attempted to work on involved trying to color scale the use% in the output of a "df -h".
Alas it didn't work as I expected it:
$ df -h | colout --scale 0,100 "([0-9]*)%" scale
ValueError: could not convert string to float:
However if I grep out just the /dev/sda line it does what I expected: $ df -h | grep /dev/sda | colout --scale 0,100 "([0-9]*)%" scale
/dev/sda 20G 3.2G 16G 17% /
The 17% is a pretty blue.Tips?
df -h | colout "([0-9]+)%" scaleTo get it working I needed to do:
sudo python3 setup.py install
And /usr/local/bin/colout was created for me (unlike what it mentions in the readme atm).It can be done with things liek $PIPESTATUS, but some sort of wrapper/function to do it would be nice.
https://github.com/nojhan/colout/commit/37934e9266d05e1519ac...
https://github.com/nojhan/colout/commit/64454e42f1cf5a4f8cd4...
Update: 37934e9 still works with python 2.6
When I drag it over to the cinema display it looks fine.
Noone else here in the office can see it, both those with good vision and those who are technically blind. Maybe I have special powers. Or a brain tumor.
EDIT: The tool is great btw :)
<red>* This is a colored line [<red>fail<end>]</end>
(You can use the `--debug` switch of colout to get hints about such problems). colout -a -s Python monokai < code.py # just like pygmentize
colout "^(:*)'(:*)'(:*)$" blue,python,blue < code.py # just the code 'inside quotes', not the rest of the lineAn easy workaround is to indicate a fake pattern argument:
colout -r x % colout -r x
usage: colout.py [-h] [-g] [-c] [-l SCALE] [-a] [-t] [-s]
REGEX [COLOR] [STYLE]
colout.py: error: unrecognized arguments: -r
:( [:~/code/colout/colout] parse_r+* ± colout -r x
Available resources:
STYLES: reverse, bold, italic, normal, conceal, rapid_blink, faint, underline, blink
COLORS: blue, none, black, yellow, cyan, green, magenta, white, red
SPECIAL: random, Random, scale, Scale, colormap
THEMES: g++, cmake, json, perm
COLORMAPS: rainbow, jet72, Spectrum, spectrum, Rainbow
LEXERS: Cucumber, abap, ada, ahk, antlr, antlr-as, antlr-cpp, antlr-csharp, antlr-java, antlr-objc, antlr-perl, antlr-python, antlr-ruby, apacheconf, applescript, as, as3, aspx-cs, aspx-vb, asy, basemake, bash, bat, bbcode, befunge, blitzmax, boo, brainfuck, c, c-objdump, cfm, cfs, cheetah, clojure, cmake, coffee-script, common-lisp, console, control, cpp, cpp-objdump, csharp, css, css+django, css+erb, css+genshitext, css+mako, css+myghty, css+php, css+smarty, cython, d, d-objdump, delphi, diff, django, dpatch, duel, dylan, erb, erl, erlang, evoque, factor, felix, fortran, gas, genshi, genshitext, glsl, gnuplot, go, gooddata-cl, groff, haml, haskell, html, html+cheetah, html+django, html+evoque, html+genshi, html+mako, html+myghty, html+php, html+smarty, html+velocity, hx, hybris, ini, io, ioke, irc, jade, java, js, js+cheetah, js+django, js+erb, js+genshitext, js+mako, js+myghty, js+php, js+smarty, jsp, lhs, lighty, llvm, logtalk, lua, make, mako, maql, mason, matlab, matlabsession, minid, modelica, modula2, moocode, mupad, mxml, myghty, mysql, nasm, newspeak, nginx, numpy, objdump, objective-c, objective-j, ocaml, ooc, perl, php, postscript, pot, pov, prolog, properties, protobuf, py3tb, pycon, pytb, python, python3, ragel, ragel-c, ragel-cpp, ragel-d, ragel-em, ragel-java, ragel-objc, ragel-ruby, raw, rb, rbcon, rconsole, rebol, redcode, rhtml, rst, sass, scala, scaml, scheme, scss, smalltalk, smarty, sourceslist, splus, sql, sqlite3, squidconf, ssp, tcl, tcsh, tex, text, trac-wiki, v, vala, vb.net, velocity, vim, xml, xml+cheetah, xml+django, xml+erb, xml+evoque, xml+mako, xml+myghty, xml+php, xml+smarty, xml+velocity, xquery, xslt, yamlls example in zsh:
alias ls="ls -lph1 --color=always"
function ls {
/bin/ls $@ | colout [regex] colours
}
This will pass all arguments after "ls" to the /bin/ls command. This also means you can keep your existing aliases clean and tidy for common params.Remember to use the full path (or /usr/bin/env maybe) so that you don't create a recursive call to your function ;)
This doesn't deal with the situation of being unable to get the return value of the original command, but depending on your needs, this may not be an issue.
(edited for spacing)