diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bd9e6617827818fd043452c08c606f07b78014a0 (patch) | |
tree | 425bb4c3168f9c02f10150f235d2cb998dcc6108 /scripts/colorcvs | |
download | tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'scripts/colorcvs')
-rwxr-xr-x | scripts/colorcvs | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/scripts/colorcvs b/scripts/colorcvs new file mode 100755 index 00000000..41c7716d --- /dev/null +++ b/scripts/colorcvs @@ -0,0 +1,175 @@ +#! /usr/bin/env perl + +# colorcvs +# +# based on colorgcc +# +# Requires the ANSIColor module from CPAN. +# +# Usage: +# +# In a directory that occurs in your PATH _before_ the directory +# where cvs lives, create a softlink to colorcvs: +# +# cvs -> colorcvs +# +# That's it. When "cvs" is invoked, colorcvs is run instead. +# +# The default settings can be overridden with ~/.colorcvsrc. +# See the colorcvsrc-sample for more information. +# +# Note: +# +# colorcvs will only emit color codes if: +# +# (1) tts STDOUT is a tty. +# (2) the value of $TERM is not listed in the "nocolor" option. +# (3) the cvs command is not a commit or import (as the text editor +# opened by cvs will often be hampered by colorcvs). +# +# If colorcvs colorizes the output, cvs's STDERR will be +# combined with STDOUT. Otherwise, colorcvs just passes the output from +# cvs through without modification. +# +# Copyright 2002 Neil Stevens <[email protected]> +# +# Copyright 1999 Jamie Moyers <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +use Term::ANSIColor; +use IPC::Open3; + +sub initDefaults +{ + $cvsPath = "/usr/bin/cvs"; + + $nocolor{"dumb"} = "true"; + + $colors{"P"} = color("reset"); + $colors{"U"} = color("reset"); + $colors{"C"} = color("bold red"); + $colors{"M"} = color("bold yellow"); + $colors{"A"} = color("cyan"); + $colors{"R"} = color("cyan"); + $colors{"?"} = color("bold"); + $colors{"server"} = color("bold green"); + $colors{"warning"} = color("bold cyan"); +} + +sub loadPreferences +{ +# Usage: loadPreferences("filename"); + + my($filename) = @_; + + open(PREFS, "<$filename") || return; + + while(<PREFS>) + { + next if (m/^\#.*/); # It's a comment. + next if (!m/(.*):\s*(.*)/); # It's not of the form "foo: bar". + + $option = $1; + $value = $2; + + if ($option =~ /cvs/) + { + $cvsPath = $value; + } + elsif ($option eq "nocolor") + { + # The nocolor option lists terminal types, separated by + # spaces, not to do color on. + foreach $termtype (split(/\s+/, $value)) + { + $nocolor{$termtype} = "true"; + } + } + else + { + $colors{$option} = color($value); + } + } + close(PREFS); +} + +# +# Main program +# + +# Set up default values for colors and cvs path. +initDefaults(); + +# Read the configuration file, if there is one. +$configFile = $ENV{"HOME"} . "/.colorcvsrc"; +if (-f $configFile) +{ + loadPreferences($configFile); +} + +# Get the terminal type. +$terminal = $ENV{"TERM"} || "dumb"; + +$commit = 0; +foreach (@ARGV) +{ + if(/^ci$/ || /^commit$/ || /^import$/) + { + $commit = 1; + } +} + +# If it's in the list of terminal types not to color, or if +# we're writing to something that's not a tty, don't do color. +if (! -t STDOUT || $commit == 1 || $nocolor{$terminal}) +{ + exec $cvsPath, @ARGV + or die("Couldn't exec"); +} + +# Keep the pid of the cvs process so we can get its return +# code and use that as our return code. +$cvs_pid = open3('<&STDIN', \*CVSOUT, \*CVSOUT, $cvsPath, @ARGV); +$cvsName = $cvsPath; +$cvsName =~ s,.*/(.*)$,\1,; + +# Colorize the output from the cvs program. +while(<CVSOUT>) +{ + chomp; + if (m/^(.) .+/) # S filename + { + print($colors{$1}, $_, color("reset")); + } + elsif (m/warning:/) # warning + { + print($colors{"warning"}, $_, color("reset")); + } + elsif (m/^$cvsName[^:]*: / || m/^cvs server: /) # server message + { + print($colors{"server"}, $_, color("reset")); + } + else # Anything else + { + # Print normally. + print(color("reset"), $_); + } + print "\n"; +} + +# Get the return code of the cvs program and exit with that. +waitpid($cvs_pid, 0); +exit ($? >> 8); |