Posts Tagged ‘dir_colors’

Blinging out your terminal, adding more colors

Thursday, August 5th, 2010

I recently installed Arch on my desktop, forsaking Ubuntu.

I still like Ubuntu and all, but it was an old version (Jaunty), too many packages were getting too badly outdated, and the one flaw with Ubuntu is that through bitter experiences I no longer trust dist-upgrades at all.

Arch promised a solution to this, in rolling upgrades. It hasn’t convinced me yet, but having given Ubuntu a chance for little over three years, Arch should get the benefit of a doubt until it does something pants-on-head-crazy at least ;)

One thing (among a whole host) I missed in Arch, which Ubuntu had done for me, was setting up dircolors so that when running the ls command some types of files (determined by their extension) would be colorized differently.

For instance, I quite liked that in Ubuntu, whenever I executed an ls in a directory containing tarballs, they’d all show up with a bright red color instead of the usual bland green.

It made it easier to locate them, which, in theory, would save me time.

So I fired up Firefox and asked Google for

archlinux colorize images and archives in ls

What Google returned was (among others) these two forum-posts:
https://bbs.archlinux.org/viewtopic.php?pid=597273
https://bbs.archlinux.org/viewtopic.php?id=17155

The first didn’t seem all that useful to me, which was why I went to the other post and found almost all I was looking for. The ~/.dir_colors in the second post didn’t have any TERM line for rxvt, but the first post did, so with a little copying and pasting voilĂ ! Colors! Colors everwhere!

So what you want to be doing is:
a. edit your ~/.bashrc (or whatever shell you’re using) adding:

if [ -f ~/.dir_colors ]; then
    eval `dircolors ~/.dir_colors`
fi

b. read the dir_color manpage to understand how the ~/.dir_colors file should be formatted and what the available color codes are. I.e.:

Attribute codes:
00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
Text color codes:
30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
Background color codes:
40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

For instance, would you want files of a certain extension to show up as blinking red text on a black background use: 05;31;40
(you probably don’t want do use that specific combination for anything ;D)

c. go crazy with colors in your ~/.dir_colors, e.g.:

# archives
.tar 01;31
.tgz 01;31
.tar.gz 01;31

# images
.jpg 01;35
.jpeg 01;35
.gif 01;35
.png 01;35

etc.

That’s all there is to it really. Changes won’t appear in any existing terminal until you source the .bashrc file but all new terminals will behave “correctly” from the start.

And in closing, a completely unrelated little Arch tip:

If you are trying to get k3b or k9copy to work and it just frakking won’t, you are most likely not part of the group “optical”.

# usermod -a -G optical YourUsernameHere

fixes that (the user added to the optical group would need to log out and in again for changes to take effect).

:wq