One (midly annoying) feature of mg is that it appends /dev/null to the
grep invocation.  I guess this was done so grep is never called with
only one file argument and so it always displays the filename in its
output.

However, this gets a bit annoying when one only types "grep -n -R foo"
and yields no results because only /dev/null was consulted.

My proposal is to add -H to the mix instead.

This poses a problem: it gets too easy to "hang" mg by forgetting the
path to the files: grep would read from stdin and since inherits the
cooked mode ^D and ^C don't work.  Diff below works around the problem
in the easier way: redirecting stdin from /dev/null.  (a follow-up
patch could rework compile_mode and clean it up a bit, avoiding the
cd'ing back and forth too, by just forking a child and redirect its
stdout with a pipe.)

(note that this issue is already present: M-x grep RET C-u "cat -" RET)

ok?

diff /home/op/w/mg.orig
commit - b83db95072ea94d64c0bb6027c4b3478e3400e5c
path + /home/op/w/mg.orig
blob - 016256f64d06be49304999fa4665018e4f823d31
file + grep.c
--- grep.c
+++ grep.c
@@ -69,14 +69,12 @@ grep(int f, int n)
        struct buffer   *bp;
        struct mgwin    *wp;
 
-       (void)strlcpy(cprompt, "grep -n ", sizeof(cprompt));
+       (void)strlcpy(cprompt, "grep -Hn ", sizeof(cprompt));
        if ((bufp = eread("Run grep: ", cprompt, NFILEN,
            EFDEF | EFNEW | EFCR)) == NULL)
                return (ABORT);
        else if (bufp[0] == '\0')
                return (FALSE);
-       if (strlcat(cprompt, " /dev/null", sizeof(cprompt)) >= sizeof(cprompt))
-               return (FALSE);
 
        if ((bp = compile_mode("*grep*", cprompt)) == NULL)
                return (FALSE);
@@ -189,7 +187,7 @@ compile_mode(const char *name, const char *command)
        buf = NULL;
        sz = 0;
 
-       n = snprintf(qcmd, sizeof(qcmd), "%s 2>&1", command);
+       n = snprintf(qcmd, sizeof(qcmd), "%s 2>&1 </dev/null", command);
        if (n < 0 || n >= sizeof(qcmd))
                return (NULL);
 

Reply via email to