Hi,

I'd like to propose a small patch for colordiff.
I like this tool, but right now colordiff still tries to colorize
output if redirected to a file. This patch (taken from colorgcc)
disables colorization in that case. In addition, it also adds a
configuration option nocolor to disable colorization for specific
terminal types.

thanks & ciao,
Mario

-- 
 Wo das Chaos auf die Ordnung trifft, gewinnt meist das Chaos,
 weil es besser organisiert ist.
     - Friedrich Nietzsche -

--
    _____    ________
   /     \  /   ____/  Mario Schwalbe
  /  \ /  \ \____  \
 /    Y    \/       \  eMail: [email protected],
 \____|__  /______  /         [email protected]
         \/       \/

          key ID: 7DA9 DAFF
      public key: https://www1.inf.tu-dresden.de/~ms790178/key.asc
 key fingerprint: 2979 AA20 4A93 B527 90CC  45E5 4B28 511A 7DA9 DAFF
--- /usr/bin/colordiff	2008-05-06 10:57:21.000000000 +0200
+++ local/scripts/colordiff	2008-12-15 01:06:59.000000000 +0100
@@ -61,6 +61,8 @@ my $file_new   = $colour{blue};
 my $diff_stuff = $colour{magenta};
 my $cvs_stuff  = $colour{green};
 
+my %nocolor=();
+
 # Locations for personal and system-wide colour configurations
 my $HOME   = $ENV{HOME};
 my $etcdir = '/etc';
@@ -94,6 +96,10 @@ foreach $config_file (@config_files) {
             }
             $setting =~ tr/A-Z/a-z/;
             $value =~ tr/A-Z/a-z/;
+            if ($setting eq 'nocolor') {
+                $nocolor{$value}='true';
+                next;
+            }
             if (($value eq 'normal') || ($value eq 'none')) {
                 $value = 'off';
             }
@@ -136,6 +142,14 @@ if ((-f STDOUT) && ($color_patch == 0)) 
     $colour{off}='';
 }
 
+# Get the terminal type. 
+my $terminal = $ENV{"TERM"} || "dumb";
+
+# 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 (! $ENV{"CDIFF_FORCE_COLOR"} && (! -t STDOUT || $nocolor{$terminal})) {
+    exec "diff", @ARGV or die("couldn't exec");
+}
 
 # ----------------------------------------------------------------------------
 # FIXME

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
Ubuntu-motu mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-motu

Reply via email to