<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,9 @@
 #!/bin/bash
 #
+# div
+#
 # easy diff visible in vimpager
-# wrote because i'm too lazy to type `diff -wu $1 $2 | vimpager`
+# wrote because i'm too lazy to type `diff -wu $1 $2 | vimpager` for all those pacnew files
 #
 # perry hargrave &gt;perrydothargraveatgmaildotcom&lt;
 # aka bioe007
@@ -10,30 +12,55 @@ SELFNAME=&quot;`basename $0`&quot;
 DIFFCMD=${DIFFCMD:-`which diff`}
 DIFFOPTS=${DIFFOPTS:-&quot;wu&quot;}
 PGR=${PAGER:-`which less`}
-
+PACSEARCHPATH=&quot;/etc&quot;
 
 #{{{ usage()
 usage() {
     cat &lt;&lt; EOF &gt;&amp;2 
-Usage as diff substitute
-    $SELFNAME [-&lt;diff options&gt;] &lt;file1&gt; &lt;file2&gt;
+Usage as diff substitute:
+    $SELFNAME [diff options] [$SELFNAME options] &lt;file1&gt; &lt;file2&gt;
 
     This invokes: 
         basecmd=$DIFFCMD -$DIFFOPTS &lt;file1&gt; &lt;file2&gt;| $PGR
+        
+            (*current settings shown)
+
+    Arguments to 'diff' can be passed just like normal, $SELFNAME assumes
+    diff -wu by default. 
 
 Usage for pacman:
-    $SELFNAME [-p|--pac]
+    $SELFNAME [-P|--Pac]
     
     This invokes a find operation to look for files suffixed with '.pacnew'
     in the /etc directory. Each pair of foo.conf and foo.conf.pacnew are 
-    diff'ed and displayed in the $PAGER
+    diff'ed and displayed in the \$PAGER
+
+$SELFNAME options:
+    --nobatch   : do not batch diff files together in \$PAGER
+                    instead view each separately in \$PAGER
+
+    --outfile=&lt;file&gt;  : Write diffs to &lt;file&gt; instead of default
+                        This file is not automatically deleted on
+                        exit.
+                        If &lt;file&gt; exists then it will be appended to
+                        NOT overwritten.
+                        *This forces batched mode*
+
+    Comments or suggestions to perry.hargrave@gmail.com
 EOF
 }
 #}}}
 
 #{{{ error()
+# if given a 2nd parameter this will not kill the script
 error() {
     echo &quot;ERROR: $SELFNAME: $1&quot;
+    test &quot;$2&quot; &amp;&amp; return\
+        || echo &quot;ERROR: $SELFNAME: giving up...&quot;
+        
+    if [ -e &quot;$TMPFILE&quot; ]; then
+        rm $TMPFILE
+    fi
     exit 1
 }
 #}}}
@@ -41,23 +68,63 @@ error() {
 #{{{ dodiff()
 dodiff() {
 
+    # current file index and number of files
     i_diff=&quot;0&quot;
-    i_last=&quot;${#fileList[*]}&quot;
+    i_last=${#fileList[*]}
+
+    # don't try and diff an odd number of files
+    let &quot;modulo=$i_last % 2&quot;
+    if ((&quot;$modulo&quot;)); then error &quot;Odd number of files given&quot;; fi
+
+    # test for batch mode
+    if ((&quot;$BATCH&quot;)) || ((&quot;$OUTFILE&quot;)); then
+        BATCH=1
+        TMPFILE=&quot;${OUTFILE:-/tmp/${SELFNAME}.${USER}.${RANDOM}.diff}&quot;
+        touch $TMPFILE || error &quot;Couldn't write to $TMPFILE&quot;
+    fi
 
+    #{{{ iterate the pairs in the file list
     while [ $i_diff -lt $i_last ]; do
 
+        # both files must be readable by the user
         if [ -r &quot;${fileList[$i_diff]}&quot; ] &amp;&amp; [ -r &quot;${fileList[$((i_diff+1))]}&quot; ] ; then
 
-            echo &quot;trying: $DIFFCMD -$DIFFOPTS ${fileList[$i_diff]} ${fileList[$((i_diff+1))]} | $PGR&quot;
+            #{{{ if --nobatch IS NOT specified or --outfile IS then batch the diffs
+            if ((&quot;$BATCH&quot;)) ; then
+                echo &quot;$SELFNAME: \`$DIFFCMD -$DIFFOPTS ${fileList[$i_diff]} ${fileList[$((i_diff+1))]} &gt;&gt; $TMPFILE'&quot;\
+                    | tee -a &quot;$TMPFILE&quot;
 
-            $DIFFCMD -$DIFFOPTS ${fileList[$i_diff]} ${fileList[$((i_diff+1))]} | $PGR
+                $DIFFCMD -$DIFFOPTS &quot;${fileList[$i_diff]}&quot; &quot;${fileList[$((i_diff+1))]}&quot; &gt;&gt; &quot;$TMPFILE&quot;
 
+            else
+
+                echo &quot;$SELFNAME: \`$DIFFCMD -$DIFFOPTS ${fileList[$i_diff]} ${fileList[$((i_diff+1))]} | $PGR'&quot;
+                $DIFFCMD -$DIFFOPTS ${fileList[$i_diff]} ${fileList[$((i_diff+1))]} | $PGR
+            fi
+            #}}}
+
+            # increment file counter
             i_diff=$((i_diff+2))
+
         else
-            error &quot;One or more specifed files unreadable&quot;
-            break
+            error &quot;Could not read ${fileList[$i_diff]} : skipping&quot; &quot;1&quot;
+            i_diff=$((i_diff+2))
+            continue
         fi
     done
+    #}}}
+    
+    if [ -e &quot;$TMPFILE&quot; ]; then
+        $PGR $TMPFILE
+
+        # remove the file if user doesn't specify --outfile
+        if [ -z &quot;$OUTFILE&quot; ]; then
+            rm &quot;$TMPFILE&quot; || error &quot;Couldn't delete $TMPFILE&quot;
+        fi
+    fi
+
+    # done
+    exit 0
 }
 #}}}
 
@@ -83,20 +150,44 @@ pacmode() {
 SW=&quot;1&quot;
 iFile=0
 fileList[$iFile]=&quot;&quot;
+unset BATCH
+BATCH=1
+
+#{{{ cli option parsing
+
+if [ &quot;$#&quot; -lt &quot;1&quot; ]; then
+    usage
+    error &quot;No command specified&quot;
+fi
+
 while [ &quot;$#&quot; -gt &quot;0&quot; ]; do
     case &quot;$1&quot; in
 
-        # parse real options
+        # parse options
         -* )
 
-        if [ &quot;$1&quot; == &quot;.-pac&quot; ] || [ &quot;$1&quot; == &quot;-p&quot; ] ; then
-            pacmode
+        if [ &quot;$1&quot; == &quot;.-Pac&quot; ] || [ &quot;$1&quot; == &quot;-P&quot; ] ; then
+            DOPAC=1
         elif [ &quot;$1&quot; == &quot;-h&quot; ] || [ &quot;$1&quot; == &quot;--help&quot; ] ; then
             usage
             exit 1
+        elif [ &quot;$1&quot; == &quot;--nobatch&quot; ] ; then
+            if [ -z &quot;$OUTFILE&quot; ]; then
+                BATCH=0
+            else
+                error &quot;--nobatch and --outfile are exclusive options&quot;
+            fi
+        elif [[ &quot;$1&quot; =~ &quot;outfile&quot; ]]; then # ! -z &quot;${1##--outfile=}&quot; ] ; then
+
+            if ((BATCH)); then
+                touch &quot;${1##--outfile=}&quot;\
+                    &amp;&amp; OUTFILE=&quot;${1##--outfile=}&quot;\
+                    || error &quot;Couldn't write to $1&quot;
+            else
+                error &quot;--nobatch and --outfile are exclusive options&quot;
+            fi
         else
             DIFFOPTS=${1#-*}
-            echo $DIFFOPTS
         fi
         ;;
 
@@ -116,7 +207,13 @@ while [ &quot;$#&quot; -gt &quot;0&quot; ]; do
 
     shift $SW
 done
+#}}}
     
+
+if [[ &quot;$DOPAC&quot; ]] ; then
+    pacmode
+fi
+
 dodiff
 
 # vim:set ft=sh fdm=marker ts=4 sw=4 et sta ai si: </diff>
      <filename>.bin/div</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7276f3c6f946f76d243e06f64f1d168bba1457f1</id>
    </parent>
  </parents>
  <author>
    <name>perry</name>
    <email>perry.hargrave@gmail.com</email>
  </author>
  <url>http://github.com/bioe007/bioe007configs/commit/cc6a2f75ae317b4dc38edc28bda7d8a9f60b69b5</url>
  <id>cc6a2f75ae317b4dc38edc28bda7d8a9f60b69b5</id>
  <committed-date>2009-11-12T11:52:45-08:00</committed-date>
  <authored-date>2009-11-12T11:52:45-08:00</authored-date>
  <message>made smartererer...</message>
  <tree>2a1a416c58218b30cab13a80323d14710772eb8f</tree>
  <committer>
    <name>perry</name>
    <email>perry.hargrave@gmail.com</email>
  </committer>
</commit>
