CURRENT PROJECTS
loading
CATEGORIES AND POSTS
loading
overset
DEVELOPMENT LOG FOR JIM PALMER
Posted 05/29/2008 in unix


UPDATE -- As per a another post on which I got awk'd - I'd figure if I could take that idea and squeeze it onto a single line instead of using a different awk file. Came up with these:
# cvs -q up -dP | awk '{a["A"]=32;a["C"]=31;a["M"]=34;a["U"]=37;a["?"]=36;printf("\033[1;%sm%s\033[0;00m\n",a[$1],$0)}'
... for CVS or for SVN:
# svn stat -q | awk '{a["A"]=32;a["C"]=31;a["M"]=34;a["G"]=37;a["D"]=36;printf("\033[1;%sm%s\033[0;00m\n",a[$1],$0)}'
Here's a quick screen of the CVS version's output:
A src/add.cs
C src/conflict.cs
M src/modified.cs
U src/updated.cs
? src/unknown.cs

As per a friend's article, Color your svn command-line output with svnc! (powerof2games has since fallen), I thought this would be a great opportunity to show how I'd do it in the BASH shell on a single line of code.

I mostly use CVS above SVN with the repository always residing on a local unix machine. This means I use the command-line for almost all versioning control - for commit, conflict resolution, merging, tagging and release, etc. - which equates to a single line shell command that can colorize the output (assuming you're on a valid TERM such as TERM=ansi) of the most used UPDATE or STAT versioning command.

Here's the CVS version (quiet output and PRUNE enabled):
cvs -q up -dP \
| sed -e "s/^\(\A.*\)$/`printf '\033'`[1;32m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\C.*\)$/`printf '\033'`[1;31m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\M.*\)$/`printf '\033'`[1;34m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\U.*\)$/`printf '\033'`[1;37m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\?.*\)$/`printf '\033'`[1;36m\1`printf '\033'`[0;00m/g"

Here's the SVN version (quiet output):
svn stat -q \
| sed -e "s/^\(\A.*\)$/`printf '\033'`[1;32m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\C.*\)$/`printf '\033'`[1;31m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\M.*\)$/`printf '\033'`[1;34m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\G.*\)$/`printf '\033'`[1;37m\1`printf '\033'`[0;00m/g" \
| sed -e "s/^\(\D.*\)$/`printf '\033'`[1;36m\1`printf '\033'`[0;00m/g"

This doesn't include all the specific file-state tags in CVS or SVN, but is a good start. The ANSI color codes are rather obvious as well - so this is open for quick modification. Maybe a PowerShell version could easily be whipped up similar to this.

If you want to alias this in UNIX for all users, setup something in the /etc/bashrc like
alias='/usr/local/bin/cu/.sh'
... and place the following at the top of the /usr/local/bin/cu/.sh file with +x permissions
#!/bin/sh
cvs -q up -dP \
...
comments
loading
new comment
NAME
EMAIL ME ON UPDATES
EMAIL (hidden)
URL
MESSAGE TAGS ALLOWED: <code> <a> <pre class="code [tab4|tabX|inline|bash]"> <br>
PREVIEW COMMENT
TURING TEST
gravatar