[PATCH] notmuch-mutt: replace gnu sed and xargs with perl

Taylor Carpenter taylor at codecafe.com
Wed Apr 11 17:29:53 PDT 2012


External software dependencies removed: sed and xargs.

Sed shell escaping is handled automatically with perl symlink function.

The xargs usage is specific to gnu xargs (fails on bsd xargs, etc).

NOTE: The current query pulls the list of files into an array all at
once.  The larger the list the more memory used.
---
 contrib/notmuch-mutt/notmuch-mutt |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index 424f9a3..c995022 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -12,6 +12,7 @@ use strict;
 use warnings;
 
 use File::Path;
+use File::Basename;
 use Getopt::Long qw(:config no_getopt_compat);
 use Mail::Internet;
 use Mail::Box::Maildir;
@@ -41,9 +42,11 @@ sub search($$) {
     $query = shell_quote($query);
 
     empty_maildir($maildir);
-    system("notmuch search --output=files $query"
-	   . " | sed -e 's: :\\\\ :g'"
-	   . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");
+    my @filelist = `notmuch search --output=files $query`;
+    foreach(@filelist) {
+        chomp;
+        symlink($_, "$maildir/cur/" . basename($_));
+    }
 }
 
 sub prompt($$) {
-- 
1.7.7.4



More information about the notmuch mailing list