Can you?
OF COURSE YOU CANT! Color is fucking awesome! No one yanks their crank to black and white shit anymore.
Once you've tasted color, you can never go back.
This brings us to the subject of version control. Over the last few years I've been spoiled by git, but have recently switched jobs and been using svn again. Using git has taught me to actually care what I'm committing — as opposed to just creating one giant commit at the end of the day — which has meant I've been looking at lots of diffs.
Git gives you lovely colorized, paged diffs that frequently stiffen the schlong. While svn, on the other hand, still gives you the same uncolored, unpaged horse shit as it did several years ago! I can't fucking believe the meat puppets at svn haven't gotten their asses into gear and stolen some basic UI ideas from the competition. WTF guys?!
Here's how you enable color for everything in git:
git config --global color.ui always
There are more granular options if you want them, but fuck that, color is awesome!
Svn has no such option. So I, like many others, have been forced to hack the mainframe to get color. Check my hacks:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Author: Martin Grenfell [http://github.com/scrooloose] | |
#License: | |
# | |
# This program is free software. It comes without any warranty, to | |
# the extent permitted by applicable law. You can redistribute it | |
# and/or modify it under the terms of the Do What The Fuck You Want | |
# To Public License, Version 2, as published by Sam Hocevar. See | |
# http://sam.zoy.org/wtfpl/COPYING for more details. | |
# | |
#This script hijacks calls to svn and adds color and pagination to | |
#some svn commands. Source it from your bashrc. | |
# | |
#colordiff must be installed. | |
#------------------------------------------------------------------- | |
#intercept calls to svn | |
svn () { | |
#bail if the user didnt specify which subversion command to invoke | |
if [ $# -lt 1 ]; then | |
command svn | |
return | |
fi | |
local sub_cmd=$1 | |
shift | |
#intercept svn diff commands | |
if [ $sub_cmd == diff ]; then | |
#colorize the diff | |
#remove stupid ^M dos line endings | |
#page it if there's more one screen | |
command svn diff "$@" | colordiff | sed -e 's/\r//g' | less -RF | |
#add some color to svn status output and page if needed: | |
#M = blue | |
#A = green | |
#D/!/~ = red | |
#C = magenta | |
# | |
#note that C and M can be preceded by whitespace - see $svn help status | |
elif [[ $sub_cmd =~ ^(status|st)$ ]]; then | |
command svn status "$@" | sed -e 's/^\(\([A-Z]\s\+\(+\s\+\)\?\)\?C .*\)$/\o33\[1;35m\1\o33[0m/' \ | |
-e 's/^\(\s*M.*\)$/\o33\[1;34m\1\o33[0m/' \ | |
-e 's/^\(A.*\)$/\o33\[1;32m\1\o33[0m/' \ | |
-e 's/^\(\(D\|!\|~\).*\)$/\o33\[1;31m\1\o33[0m/' | less -RF | |
#page some stuff I often end up paging manually | |
elif [[ $sub_cmd =~ ^(blame|help|h|cat)$ ]]; then | |
command svn $sub_cmd "$@" | less -F | |
#colorize and page svn log | |
#rearrange the date field from: | |
# 2010-10-08 21:19:24 +1300 (Fri, 08 Oct 2010) | |
#to: | |
# 2010-10-08 21:19 (Fri, +1300) | |
elif [[ $sub_cmd == log ]]; then | |
command svn log "$@" | sed -e 's/^\(.*\)|\(.*\)| \(.*\) \(.*\):[0-9]\{2\} \(.*\) (\(...\).*) |\(.*\)$/\o33\[1;32m\1\o33[0m|\o33\[1;34m\2\o33[0m| \o33\[1;35m\3 \4 (\6, \5)\o33[0m |\7/' | less -RF | |
#let svn handle it as normal | |
else | |
command svn $sub_cmd "$@" | |
fi | |
} | |
# vi:sw=2:et:sts=2 |
This script defines a function called "svn" that hijacks calls to the svn program and essentially rewrites some of the commands. For example, this command:
svn diff -r1:7 foo
would get rewritten to:
svn diff -r1:7 foo | colordiff | sed -e 's/\r//g' | less -RF
Another example:
svn log foo
would get rewritten to:
svn log foo | less -F
Notice that I'm still interacting with svn via the same command set, and am not training myself away from the existing commands. Hopefully this will prevent me from losing the plot and ripping off cocks when forced to use svn on a machine that doesn't have my hacks.