TarColor: color the output of tar tvf similarly to the way GNU ls would

One day I was looking through a tar file and looking for an executable. When I use ls, I can do this at a glance by just looking for green filenames, as I always have my ls configured to show executable files in green. It occurred to me that it would be nice to see the same kind of coloring when looking at the contents of tar files with tar tvf. Thus, TarColor was born. It was a quick Perl script to scratch my own itch. I thought others might find it useful, so I put it on GitHub and CPAN.

Usage

You can use tarcolor manually like this:

$ tar tvf some_tarball.tgz | tarcolor
... colored output ...

There is also a bundled shell script (for bash and zsh) that makes tar automatically pipe its output through tarcolor:

$ source /usr/local/etc/tarcolor/tarcolorauto.sh
$ tarcolorauto on
$ tar tvf some_tarball.tgz
... colored output ...
$ tarcolorauto off
$ tar tvf some_tarball.tgz
... normal uncolored output ...

Customization

Colors can be customized using the LS_COLORS or TAR_COLORS environment variables:

$ export LS_COLORS='di=01;34:ln=01;36:ex=01;32:so=01;40:pi=01;40:bd=40;33
:cd=40;33:su=0;41:sg=0;46'

The format for LS_COLORS and TAR_COLORS is the same format used by LS_COLORS (used by GNU ls). So if you use GNU ls and have your LS_COLORS set, then tarcolor will use similar colors as ls. If you want to tweak your colors and don’t want to edit LS_COLORS manually, you might try this online LS_COLORS generator.

Links

Leave a Reply

Your email address will not be published.