Hacker News new | comments | show | ask | jobs | submit login
Grc - it's like stylesheets for your terminal (wynnnetherland.com)
155 points by netherland on Apr 18, 2012 | hide | past | web | favorite | 37 comments

Solarized provides a great mapping table between terminal color names and various color spaces.

Have to disagree slightly with this. Solarized is a great starting point, but, last time I checked, using the provided mapping table leads bold green, bold blue, and (most importantly) nonbold white to all become nearly-indistinguishable shades of grey. This alone damages the utility of the normally-colorized output of `ls`, as well as any tools that expect bold and nonbold versions of the same color to be roughly the same hue.

If you can stand losing Solarized's ability to swap back and forth between light and dark modes, I highly recommend tweaking it to your needs rather then relying on the default.

Similar problem here - I tried Solarized for a while and found that it was too low contrast for my tastes.

I switched to Tim Pope's vividchalk.vim and have been quite happy ever since:


I use different .Xdefaults for my shell "styling" and are incredibly happy with it. Changing to another theme is just one xrdb -merge away.

this goes a little further i guess. you can add color to regexp matches for command outputs.

Apparently. Judging from what it does the implementation could be a nice example of layering shell tools on top of each other to get new functionality. Probably it has some uses for people that work entirely with the shell.

Meh. Because I'm a Real Man with Real Big Balls I still think terminal text should come in one of three colors: green, amber, and page white. And you choose the color when you buy the terminal.

Kidding aside, I do do all my coding in an xterm that's had the font set to Glass Tty VT220 and the color set to one of those. Text decoration for highlighting purposes is done with our old friends bold, underline, and reverse video. But I'm retro like that.

You are so cool. How can I be cool like you are cool?

echo -e '\033[0;32m'

EDIT: Of course, real hackers use a rainbow shell prompt. (http://www.termsys.demon.co.uk/vtansi.htm) Building one of these is left as an exercise for the reader.

Over the years this has been a hobby of mine to colorize the shell on Linux or at least make it easier on my eyes. The best results I've had relied on the following features:

    1. Screen. Screen allowed me to colorize the hardstatusline at the bottom of the page. You can also set the hardstatus line so it updates to show the open application. Watch the video at the bottom of the screen and when I open Vim and how it updates the tab name on the hardstatus line.

    2. Using zsh. Zsh allows you to set the right hand prompt and its color.

    3. Using Xterm. Xterm allow me to launch it with any parameters controlling font, background color, foreground color, font size etc. The font I found that work the best was "Liberation Mono".

    4. Colorize the prompt. Pretty standard.
HEre is a video making use of all these features except for zsh. This was back when I used bash.


Thanks. Actually, that video is about cut-n-paste. The michaelkelleher.info site mentioned in the video no longer works. Do you have an updated one?

Essentially running a regex and applying colors. Very cool for simple applications.

Given how difficult regexs are to write properly, this probably doesn't scale well. Sadly, there isn't a DOM for terminal applications.

I'm sure someone here will know the answer for this off the top of their head so.. how does this work under the hood? How does it get to act as a sort of 'filter' for stdout?

I've recently seen a system that can 'record' your terminal session for replay on the Web - http://ascii.io/ - whose 'recorder' forks off a psuedo terminal for this (https://github.com/sickill/ascii.io-cli/blob/master/bin/asci...). Would something like Grc use a similar approach or is there another way?

I got this silly idea how to do it, I don't know if it works:

1. export your real $PATH to eg $REAL_PATH

2. clear $PATH (or set it to some dummy value)

3. Attach a wrapper script to command_not_found_handler, which would call the original command with REAL_PATH and pipes it to your filter (or colorizer or whatever).

This script inserts terminal escape sequences into text. These sequences are just text that the terminal interpret as color transitions.

Ascii.io transforms these terminal escape sequences into html/css, so Grc should work fine with it.

This script inserts terminal escape sequences into text.

I understand that part. But there's a screenshot where a "ping" is being done at a normal looking terminal and it just works without being explicitly piped through a program that does the above. What's the mechanism for piping all the terminal output through another process?

The initial grc command aliases commands like 'ping' to a modified command that processes the output[1].

[1] https://github.com/mxcl/homebrew/blob/7bbe7e9311ce95a141bf5f...

Ahh, aliases. Thanks :-) Makes sense. I was probably dreaming of a world where it'd pick up an IP address by regex in any terminal output.

Those are supplied if you source the aliases that ship with the Homebrew formula: https://github.com/mxcl/homebrew/blob/7bbe7e9311ce95a141bf5f...

I had an idea like this a while back, but as far as I know there is no shell support for it. Basically, you would install decorators in your current shell instance. The decorator could act as a filter for all stream io. Then you would not need any special commands or aliases, just configuration for how to highlight patterns.

To answer how programs like script (a little like ascii.io, but from decades ago and shipped with every Unix system), check out the manual page for forktty.

I don't give a rat ass for over coloring stuff in the terminal. I like when only what helps readability is colored.

But then again I do like some fancy stuff. And I noticed the author uses a unicode char in his prompt. While it breaks the \$ functionality ($|#) it looks neat, and I didn't think of that.

pretty cool export PS1="\u@\h \w ʎ"

for the record he uses \u26A1 aka high voltage sign ;-)

We start by assuming everyone uses OSX.

> Install via your favorite package manager. I'm on OS X so I use Homebrew:

In fairness I just installed grc on ubuntu and it is nothing like demonstrated on the blog because the homebrew version has extra stuff in it.

So "Start by assuming OSX" isn't THAT much of a smarmy reply.

> because the homebrew version has extra stuff in it.

Lies! brew edit grc shows that it's just plain grc 1.4.

At least the installation script adds some aliases to .bashrc.


It suggests to, via you voluntarily typing

    echo 'source "`brew --prefix grc`/etc/grc.bashrc"' >> ~/.bashrc

Note that if you're an Emacs user and you execute commands from inside Emacs, there is already a framework for colorization in the fontify-* or highlight-* functions.

This is interesting - I actually wrote a tool very similar to Grc a while back:


It uses the same idea of config files specifying what regexes to look for and how to color them. This tools looks a little more full-featured and tested though.

Also, I only thought of applying it to highlighting log files. I didn't think of using aliases to improve the appearance of regular terminal commands.

Netherland - I installed this and gave it a try. I'm running into one major issue. I can't see my prompt (or the last line in whatever I'm doing). I don't mess around and invoke grc by doing 'grc bash'. This now listens for every command that's in the config file. Well the command I want to work most of all is ssh. When I ssh into another system I don't see my prompt. Any ideas what I can do to fix this?

If you're using Terminal.app, the first thing you should do is installing an eye-friendly color theme. Check out Optometrist: https://github.com/pstadler/optometrist

I misread the title "it's like cheatsheets for your terminal" and now I can't help wondering if such thing exists. I know there is man but it doesn't exactly have a cheatsheet format. Anyone?

You're probably looking for cheat. http://cheat.errtheblog.com/

Does anyone have trouble with tmux displaying colours?

I tried a custom git log query that coloured the custom ordered responses. Rather than showing the text in colour, there were inline codes being displayed.

Does it work ok without tmux? If not, does git print directly to the terminal, or does it pipe to another program (like a pager)? Most programs make an isatty check in this case, but if you force printing of escape codes and pipe the output to less for example, you'll see the codes in the output instead of their effects.

Actually, I think you're right, I probably was piping to less at the time (which tmux makes me do more of than usual).

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact