Gwynne's Blog

Sa souvraya niende misain ye

String parsing No Comments

String parsing in C is painful and annoying.

I want to parse the components of an absolute POSIX path. Here’s the code to do it in several languages.

(more…)
, , , , , , ,
February 2, 2010 at 2:21 am

Terminal coloring 1 Comment

Ah, the wonderful world of the command line. I wouldn’t be able to look at myself in the mirror (and by mirror, I mean reflection in my monitor) if I couldn’t play the shell as if it were a finely tuned 128-key instrument. But I like to add a little pizzaz to the very black-and-white (or black-and-amber, or black-and-green) world of Terminal.

To do this, one adds ANSI color codes to things. Pass a proper flag or two to ls, set CLICOLOR in your environment, and most of all, set your PS1 to something interesting. Here’s mine for my local machine:

PS1='\[\033[35m\]\u@\h\[\033[00m\]:\[\033[94m\]\w\[\033[96m\]\$\[\033[00m\] '

The result looks something like this:

gwynne@localhost:~/Desktop$ _
(more…)
, , , , , , ,
January 29, 2010 at 7:10 am