Warning, /sdk/kde-dev-scripts/colorcvs is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env perl 0002 0003 # colorcvs 0004 # 0005 # based on colorgcc 0006 # 0007 # Requires the ANSIColor module from CPAN. 0008 # 0009 # Usage: 0010 # 0011 # In a directory that occurs in your PATH _before_ the directory 0012 # where cvs lives, create a softlink to colorcvs: 0013 # 0014 # cvs -> colorcvs 0015 # 0016 # That's it. When "cvs" is invoked, colorcvs is run instead. 0017 # 0018 # The default settings can be overridden with ~/.colorcvsrc. 0019 # See the colorcvsrc-sample for more information. 0020 # 0021 # Note: 0022 # 0023 # colorcvs will only emit color codes if: 0024 # 0025 # (1) tts STDOUT is a tty. 0026 # (2) the value of $TERM is not listed in the "nocolor" option. 0027 # (3) the cvs command is not a commit or import (as the text editor 0028 # opened by cvs will often be hampered by colorcvs). 0029 # 0030 # If colorcvs colorizes the output, cvs's STDERR will be 0031 # combined with STDOUT. Otherwise, colorcvs just passes the output from 0032 # cvs through without modification. 0033 # 0034 # Copyright 2002 Neil Stevens <neil@qualityassistant.com> 0035 # 0036 # Copyright 1999 Jamie Moyers <jmoyers@geeks.com> 0037 # 0038 # This program is free software; you can redistribute it and/or modify 0039 # it under the terms of the GNU General Public License as published by 0040 # the Free Software Foundation; version 2 of the License as published 0041 # by the Free Software Foundation. 0042 # 0043 # This program is distributed in the hope that it will be useful, 0044 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0045 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0046 # GNU General Public License for more details. 0047 # 0048 # You should have received a copy of the GNU General Public License 0049 # along with this program; if not, write to the Free Software 0050 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0051 0052 use Term::ANSIColor; 0053 use IPC::Open3; 0054 0055 sub initDefaults 0056 { 0057 $cvsPath = "/usr/bin/cvs"; 0058 0059 $nocolor{"dumb"} = "true"; 0060 0061 $colors{"P"} = color("reset"); 0062 $colors{"U"} = color("reset"); 0063 $colors{"C"} = color("bold red"); 0064 $colors{"M"} = color("bold yellow"); 0065 $colors{"A"} = color("cyan"); 0066 $colors{"R"} = color("cyan"); 0067 $colors{"?"} = color("bold"); 0068 $colors{"server"} = color("bold green"); 0069 $colors{"warning"} = color("bold cyan"); 0070 } 0071 0072 sub loadPreferences 0073 { 0074 # Usage: loadPreferences("filename"); 0075 0076 my($filename) = @_; 0077 0078 open(PREFS, "<$filename") || return; 0079 0080 while(<PREFS>) 0081 { 0082 next if (m/^\#.*/); # It's a comment. 0083 next if (!m/(.*):\s*(.*)/); # It's not of the form "foo: bar". 0084 0085 $option = $1; 0086 $value = $2; 0087 0088 if ($option =~ /cvs/) 0089 { 0090 $cvsPath = $value; 0091 } 0092 elsif ($option eq "nocolor") 0093 { 0094 # The nocolor option lists terminal types, separated by 0095 # spaces, not to do color on. 0096 foreach $termtype (split(/\s+/, $value)) 0097 { 0098 $nocolor{$termtype} = "true"; 0099 } 0100 } 0101 else 0102 { 0103 $colors{$option} = color($value); 0104 } 0105 } 0106 close(PREFS); 0107 } 0108 0109 # 0110 # Main program 0111 # 0112 0113 # Set up default values for colors and cvs path. 0114 initDefaults(); 0115 0116 # Read the configuration file, if there is one. 0117 $configFile = $ENV{"HOME"} . "/.colorcvsrc"; 0118 if (-f $configFile) 0119 { 0120 loadPreferences($configFile); 0121 } 0122 0123 # Get the terminal type. 0124 $terminal = $ENV{"TERM"} || "dumb"; 0125 0126 $commit = 0; 0127 foreach (@ARGV) 0128 { 0129 if(/^ci$/ || /^commit$/ || /^import$/) 0130 { 0131 $commit = 1; 0132 } 0133 } 0134 0135 # If it's in the list of terminal types not to color, or if 0136 # we're writing to something that's not a tty, don't do color. 0137 if (! -t STDOUT || $commit == 1 || $nocolor{$terminal}) 0138 { 0139 exec $cvsPath, @ARGV 0140 or die("Couldn't exec"); 0141 } 0142 0143 # Keep the pid of the cvs process so we can get its return 0144 # code and use that as our return code. 0145 $cvs_pid = open3('<&STDIN', \*CVSOUT, \*CVSOUT, $cvsPath, @ARGV); 0146 $cvsName = $cvsPath; 0147 $cvsName =~ s,.*/(.*)$,\1,; 0148 0149 # Colorize the output from the cvs program. 0150 while(<CVSOUT>) 0151 { 0152 chomp; 0153 if (m/^(.) .+/) # S filename 0154 { 0155 print($colors{$1}, $_, color("reset")); 0156 } 0157 elsif (m/warning:/) # warning 0158 { 0159 print($colors{"warning"}, $_, color("reset")); 0160 } 0161 elsif (m/^$cvsName[^:]*: / || m/^cvs server: /) # server message 0162 { 0163 print($colors{"server"}, $_, color("reset")); 0164 } 0165 else # Anything else 0166 { 0167 # Print normally. 0168 print(color("reset"), $_); 0169 } 0170 print "\n"; 0171 } 0172 0173 # Get the return code of the cvs program and exit with that. 0174 waitpid($cvs_pid, 0); 0175 exit ($? >> 8);