From e1a71a84b1cd910172360d6b7d6d44832961b273 Mon Sep 17 00:00:00 2001
From: Sorin Ionescu <sorin.ionescu@gmail.com>
Date: Sun, 29 Jan 2012 16:32:01 -0500
Subject: [PATCH] Fixed Perl find/substitute options, added inverse.

---
 plugins/perl/completions/_prep |  1 +
 plugins/perl/functions/prep    | 12 +++++++-----
 plugins/perl/functions/psub    |  7 ++++---
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/plugins/perl/completions/_prep b/plugins/perl/completions/_prep
index c1c939ee..338e4b05 100644
--- a/plugins/perl/completions/_prep
+++ b/plugins/perl/completions/_prep
@@ -5,6 +5,7 @@ _arguments \
   '-i[ignore case]' \
   '-m[^ and $ match the start and the end of a line]' \
   '-s[. matches newline]' \
+  '-v[invert match]' \
   '-x[ignore whitespace and comments]' \
   '1::pattern:' \
   '2::files:_files' && return 0
diff --git a/plugins/perl/functions/prep b/plugins/perl/functions/prep
index 3bc8b5af..2f5a60b3 100644
--- a/plugins/perl/functions/prep
+++ b/plugins/perl/functions/prep
@@ -1,6 +1,6 @@
-# Perl grep since 'grep -P' is terrible.
+# Perl Grep
 
-local usage pattern modifiers
+local usage pattern modifiers invert
 
 usage="$(
 cat <<EOF
@@ -10,16 +10,18 @@ options:
   -i    ignore case
   -m    ^ and $ match the start and the end of a line
   -s    . matches newline
+  -v    invert match
   -x    ignore whitespace and comments
 EOF
 )"
 
-while getopts ':igmxe::' opt; do
+while getopts ':imsxv' opt; do
   case "$opt" in
     (i) modifiers="${modifiers}i" ;;
     (m) modifiers="${modifiers}m" ;;
+    (s) modifiers="${modifiers}s" ;;
     (x) modifiers="${modifiers}x" ;;
-    (e) modifiers="${modifiers}e" ;;
+    (v) invert="yes" ;;
     (:)
       print "$0: option requires an argument: $OPTARG" >&2
       print "$usage" >&2
@@ -42,5 +44,5 @@ fi
 pattern="$1"
 shift
 
-perl -n -l -e "print if m/${pattern//\//\\/}/${modifiers}" "$@"
+perl -n -l -e "print if ${invert:+not} m/${pattern//\//\\/}/${modifiers}" "$@"
 
diff --git a/plugins/perl/functions/psub b/plugins/perl/functions/psub
index e88d4bdc..40fd286c 100644
--- a/plugins/perl/functions/psub
+++ b/plugins/perl/functions/psub
@@ -15,13 +15,13 @@ options:
 EOF
 )"
 
-while getopts ':igmxe::' opt; do
+while getopts ':gimsx' opt; do
   case "$opt" in
-    (i) modifiers="${modifiers}i" ;;
     (g) modifiers="${modifiers}g" ;;
+    (i) modifiers="${modifiers}i" ;;
     (m) modifiers="${modifiers}m" ;;
+    (s) modifiers="${sodifiers}s" ;;
     (x) modifiers="${modifiers}x" ;;
-    (e) modifiers="${modifiers}e" ;;
     (:)
       print "$0: option requires an argument: $OPTARG" >&2
       print "$usage" >&2
@@ -46,3 +46,4 @@ replacement="$2"
 repeat 2 shift
 
 perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@"
+