From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18268 invoked from network); 2 Feb 2022 23:14:54 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 2 Feb 2022 23:14:54 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 4ess; Wed Feb 2 18:08:21 -0500 2022 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 1ada2683 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Wed, 2 Feb 2022 15:01:08 -0800 (PST) Message-ID: To: 9front@9front.org Date: Wed, 02 Feb 2022 18:01:07 -0500 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: mobile element NoSQL-oriented singleton Subject: [9front] grep: always show path with '-n' Reply-To: 9front@9front.org Precedence: bulk With the new 'g', I noticed that sometimes we'd fail to show the filename; this happens because 'g' now uses xargs, and if there's exactly one file picked up by xargs, the Hflag does not get set. This change makes grep now print the filename if Hflag *or* Nflag is set, which is what I'd expect. Before: % grep -n -- Nflag main.c 106: flag |= Nflag; /* count only */ After: % grep -n -- Nflag main.c main.c:106: flag |= Nflag; /* count only */ And it still does something sensible for stdin: % grep -n asdf asdf stdin:1: asdf Does this make sense to people? diff 251c3cfd610abd169676852d301a2aa1267c0e57 uncommitted --- a/sys/src/cmd/grep/main.c +++ b/sys/src/cmd/grep/main.c @@ -180,7 +180,7 @@ count++; if(flag & (Cflag|Sflag|Llflag|LLflag)) goto cont; - if(flag & Hflag) + if(flag & (Hflag|Nflag)) Bprint(&bout, "%s:", file); if(flag & Nflag) Bprint(&bout, "%ld: ", lineno); @@ -219,7 +219,7 @@ count++; if(flag & (Cflag|Sflag|Llflag|LLflag)) goto conti; - if(flag & Hflag) + if(flag & (Hflag|Nflag)) Bprint(&bout, "%s:", file); if(flag & Nflag) Bprint(&bout, "%ld: ", lineno);