Skip to content

Instantly share code, notes, and snippets.

@johnjohndoe
Created February 10, 2012 15:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnjohndoe/1790203 to your computer and use it in GitHub Desktop.
Save johnjohndoe/1790203 to your computer and use it in GitHub Desktop.
Colorize SVN
# Colorize SVN
# ------------
# Adds color to the output of commands like svn status and svn update.
# The original version of the script was posted by Ash_ on Stackoverflow
# Source: http://stackoverflow.com/questions/8786400/svn-add-colors-on-command-line-svn-with-awk-in-bash
function svn {
# Skip the color script when running an svn commit.
if [ "x$1" = "xci" ] || [ "x$1" = "xcommit" ] || [ "x$1" = "xadd" ]
then
command svn "$@";
return;
fi
# Pipe svn through awk to colorize its output.
command svn "$@" | awk '
BEGIN {
cpt_c=0;
}
{
if ($1=="C") {
cpt_c=cpt_c+1;
print "\033[31m" $0 "\033[00m"; # Conflicts are displayed in red
}
else if ($1=="M") {
print "\033[31m" $0 "\033[00m"; # Modified in red
}
else if ($1=="A") {
print "\033[32m" $0 "\033[00m"; # Add in green
}
else if ($1=="?") {
print "\033[36m" $0 "\033[00m"; # New in cyan
}
else if ($1=="D") {
print "\033[31m" $0 "\033[00m"; # Delete in red
}
else if ($1=="U") {
print "\033[35m" $0 "\033[00m"; # Updated in light magenta
}
else if ($1=="X") {
print "\033[33m" $0 "\033[00m"; # No changes in yellow.
}
else if ($1=="At" || $1 == "External") {
print "\033[33m" $0 "\033[00m"; # Revision numbers in brown.
}
else {
print $0; # No color, just print the line
}
}
END {
print cpt_c, " conflicts are found.";
}';
}
@4wk-
Copy link

4wk- commented Feb 15, 2012

In standard configuration (svn only), note that discovered conflicts are stopping the script : indeed, when a file is conflicted, svn is handed over to the user, to let him type a few letters (see below)

# svn update
Conflict discovered in 'test.txt'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options:

Please follow the discussion on Stackoverflow

@arvind-clarion
Copy link

hi its good but is we can also color to see which code we delete and which we updated like git ++ and -- with color

@benkrikler
Copy link

This was great!

To be able to redirect the output of these commands nicely though, I've added a bash test for tty output to the check for svn commit or add so that line 8 now reads:

 if [ "x$1" = "xci" ] || [ "x$1" =  "xcommit" ] || [ "x$1" = "xadd" ] || [ ! -t 1 ]

which gives something like the standard --color=auto option for other commands (grep, ls etc).

@4wk-
Copy link

4wk- commented Jun 2, 2017

Hello guys,

I'm the initial author of this snippet, and I've decided to bring it back to life: https://github.com/4wk-/beautifulSVN

@arvind-clarion: in the past few years, I already made this feature. See the link above ;)
@benkrikler: in my updated version, the svn add command is supported with beautifulSVN. Could you please try it, and let me now if you have any trouble? So far, I never encountered any difficulties with this specific sub-command, but I'ld be glad to fix it ;)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment