Sfoglia il codice sorgente

enable my RSE patchset by default and provide my partial mtn(1) command colorization

Ralf S. Engelschall 18 anni fa
parent
commit
0d0c5d208a

+ 46 - 0
monotone/monotone-colorize.bashrc

@@ -0,0 +1,46 @@
+##
+##  monotone-colorize -- colorize output of mtn(1)
+##  Copyright (c) 2007 Ralf S. Engelschall <rse@engelschall.com> 
+##
+##  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; either version 2 of the License, or
+##  (at your option) any later version.
+##
+##  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, or contact Ralf S. Engelschall <rse@engelschall.com>.
+##
+##  monotone-colorize.bashrc: shell integration (language: GNU Bash)
+##
+
+#   wrap mtn(1) command for colorization via monotone-colorize(1)
+mtn () {
+    case "$1" in
+        s|st|sta|stat|statu|status )
+            shift
+            @l_prefix@/bin/mtn status ${1+"$@"} |\
+            @l_prefix@/bin/monotone-colorize status
+            ;;
+        l|lo|log )
+            shift
+            @l_prefix@/bin/mtn log ${1+"$@"} |\
+            @l_prefix@/bin/monotone-colorize log
+            ;;
+        d|di|dif|diff )
+            shift
+            @l_prefix@/bin/mtn --quiet diff --no-show-header ${1+"$@"} |\
+            @l_prefix@/bin/monotone-colorize diff
+            ;;
+        * )
+            @l_prefix@/bin/mtn ${1+"$@"}
+            ;;
+    esac
+}  
+

+ 103 - 0
monotone/monotone-colorize.pl

@@ -0,0 +1,103 @@
+#!@l_prefix@/bin/perl
+##
+##  monotone-colorize -- colorize output of mtn(1)
+##  Copyright (c) 2007 Ralf S. Engelschall <rse@engelschall.com> 
+##
+##  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; either version 2 of the License, or
+##  (at your option) any later version.
+##
+##  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, or contact Ralf S. Engelschall <rse@engelschall.com>.
+##
+##  monotone-colorize.pl: filter implementation (language: Perl)
+##
+
+require 5.008;
+use Term::ANSIColor qw(color);
+
+#   color definitions
+my $color = {
+    -standout => color("bold"),
+    -inverse  => color("bold white on_black"),
+    -positive => color("blue"),
+    -negative => color("red"),
+    -none     => color("reset"),
+};
+
+#   if connected to the TTY, colorize and connect to less(1)
+my $ontty = 0;
+if (-t STDOUT) {
+    $ontty = 1;
+    open(FP, "|@l_prefix@/bin/less -E -r");
+    *STDOUT = *FP;
+}
+
+#   determine mtn(1) command
+my $cmd = shift(@ARGV);
+
+#   process mtn(1) output
+my $in = { -changelog => 0 };
+while (<STDIN>) {
+    if ($ontty) {
+        #   dispatch according to mtn(1) command
+        if ($cmd eq "status") {
+            #   colorize headers
+            s/^(Current branch:\s+)(\S+)/$1$color->{-standout}$2$color->{-none}/o;
+            s/^(Changes against parent\s+)(\S+)/$1$color->{-standout}$2$color->{-none}/o;
+
+            #   colorize status list
+            s/^(\s+patched\s+)(\S+)/$1$color->{-positive}$2$color->{-none}/o;
+            s/^(\s+dropped\s+)(\S+)/$1$color->{-negative}$2$color->{-none}/o;
+            s/^(\s+added\s+)(\S+)/$1$color->{-standout}$color->{-positive}$2$color->{-none}/o;
+        }
+        elsif ($cmd eq "log") {
+            #   colorize certs
+            s/(Revision:\s+)(\S+)/$color->{-inverse}$1$2$color->{-none}/o;
+            s/((?:Ancestor|Author|Date|Branch|Tag):\s+)(\S+)/$1$color->{-standout}$2$color->{-none}/o;
+
+            #   colorize changelog text
+            if (m/---------------+/s) {
+                $in->{-changelog} = 0;
+                s/^([\s|\\\/o]\s*)(---+)\r?\n$/$1.("_" x 78)."\n"/oes;
+            }
+            s/^([\s|\\\/o]\s*)(.+)$/$1$color->{-positive}$2$color->{-none}/o if ($in->{-changelog});
+            $in->{-changelog} = 1 if (m/ChangeLog:\s*$/s);
+        }
+        elsif ($cmd eq "diff") {
+            #   expand tabs
+            1 while (s/\t/" " x (8 - ((length($`)-1) % 8))/e);
+         
+            #   colorize diff header
+            s/^Index:\s+(\S+).*$/("_" x 78)."\n"."$color->{-inverse}    ".$1."    $color->{-none}\n"/oes;
+            s/^========+\s*$//os;
+         
+            #   colorize unified diff
+            s/^(@@.*$)/$color->{-standout}$1$color->{-none}/o;
+            s/^(\+.*)$/$color->{-positive}$1$color->{-none}/o;
+            s/^(---\s+\S+\s+.+)$/$color->{-negative}$1$color->{-none}/o;
+            s/^(-([^-].*|))$/$color->{-negative}$1$color->{-none}/o;
+         
+            #   colorize context diff
+            s/^(--- \d+,\d+ ----.*)$/$color->{-standout}$1$color->{-none}/o;
+            s/^(\*\*\* \d+,\d+ *\*\*\*.*)$/$color->{-standout}$1$color->{-none}/o;
+            s/^(\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*)$/$color->{-standout}$1$color->{-none}/o;
+            s/^(!.*)$/$color->{-positive}$1$color->{-none}/o;
+        }
+    }
+    print STDOUT $_;
+}
+
+#   close connection to less(1)
+if ($ontty) {
+    close(FP);
+}
+

+ 7 - 0
monotone/monotone.bashrc

@@ -0,0 +1,7 @@
+##
+##  monotone.bashrc: Montone shell integration
+##
+
+source @l_prefix@/etc/monotone/monotone-complete.bashrc
+source @l_prefix@/etc/monotone/monotone-colorize.bashrc
+

+ 16 - 4
monotone/monotone.spec

@@ -33,15 +33,18 @@ Class:        EVAL
 Group:        SCM
 License:      GPL
 Version:      0.36
-Release:      20070909
+Release:      20070910
 
 #   package options
-%option       with_rse  no
+%option       with_rse  yes
 
 #   list of sources
 Source0:      http://monotone.ca/downloads/%{version}/monotone-%{version}.tar.gz
 Source1:      rc.monotone
 Source3:      monotone-setup.sh
+Source4:      monotone-colorize.pl
+Source5:      monotone-colorize.bashrc
+Source6:      monotone.bashrc
 Patch0:       monotone.patch
 Patch1:       monotone.patch.rse
 
@@ -49,7 +52,7 @@ Patch1:       monotone.patch.rse
 Prefix:       %{l_prefix}
 BuildRoot:    %{l_buildroot}
 BuildPreReq:  OpenPKG, openpkg >= 20040130, gcc, gcc::with_cxx = yes
-PreReq:       OpenPKG, openpkg >= 20040130, apg, diffutils, perl, perl-mail
+PreReq:       OpenPKG, openpkg >= 20040130, apg, diffutils, perl, perl-mail, perl-term, less
 BuildPreReq:  boost, zlib
 PreReq:       boost, zlib
 AutoReq:      no
@@ -128,7 +131,16 @@ AutoReqProv:  no
         $RPM_BUILD_ROOT%{l_prefix}/bin/monotone-notify
     %{l_shtool} install -c -m 644 \
         contrib/monotone.bash_completion \
-        $RPM_BUILD_ROOT%{l_prefix}/etc/monotone/monotone.bashrc
+        $RPM_BUILD_ROOT%{l_prefix}/etc/monotone/monotone-complete.bashrc
+    %{l_shtool} install -c -m 644 %{l_value -s -a} \
+        %{SOURCE monotone-colorize.bashrc} \
+        $RPM_BUILD_ROOT%{l_prefix}/etc/monotone/
+    %{l_shtool} install -c -m 755 %{l_value -s -a} \
+        %{SOURCE monotone-colorize.pl} \
+        $RPM_BUILD_ROOT%{l_prefix}/bin/monotone-colorize
+    %{l_shtool} install -c -m 644 %{l_value -s -a} \
+        %{SOURCE monotone.bashrc} \
+        $RPM_BUILD_ROOT%{l_prefix}/etc/monotone/
 
     #   install setup script
     %{l_shtool} mkdir -f -p -m 755 \