From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <9front-bounces@9front.inri.net> X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: from 9front.inri.net (9front.inri.net [168.235.81.73]) by inbox.vuxu.org (Postfix) with ESMTP id 2CEB026752 for ; Wed, 26 Jun 2024 04:26:32 +0200 (CEST) Received: from mail-4018.proton.ch ([185.70.40.18]) by 9front; Tue Jun 25 22:24:47 -0400 2024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shurizzle.dev; s=protonmail2; t=1719368684; x=1719627884; bh=3b6WT7K7OGa7Q+8cch8KCB9+oAgG5r6GAwiw0gHgbu8=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=KPAWjqoBs+h7OGrve0PWJAOmyQ22fUZVZCQ95+AxANU0LOxbYJEGwRHjBsUUXzSxv 68E4CD0fgNws/VTJEPcScybBTEpoJgibM4xp0ZhmNZt2d/rsEnclixsldRWROavquQ ZL+NhSwQv29jgw2HhmQiu7lpuMv744Q+ZPRV5zVvGqI5hLOd2LcceK4G+MPO7h18HZ a0oF2bR9D7IZh9GzpQzmFcil6LZOklXE6niZw3K75gUlcK/uYycu1cByXd51J8E+wJ DnhcrgS7CHEkgU32eYF7l+GiAx4A/VZiFb23lqIRXPGDuIdORvWuFUNTZaVIhjB/Xa Jr7iD1pA8paxg== Date: Wed, 26 Jun 2024 02:24:38 +0000 To: 9front@9front.org From: shurizzle Message-ID: Feedback-ID: 93734745:user:proton X-Pm-Message-ID: 3ae563d630eeac9127009af6926871ba25722a19 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: session descriptor XMPP replication high-performance engine Subject: [9front] [PATCH] feat(grep): add -H flag Reply-To: 9front@9front.org Precedence: bulk -H is the opposite of -h. When present, print the file name even if only one file is passed in the parameters. --- diff a71a76745b5fd2f3e50778268bc2cad262748416 db274004a40a00a08021473b56891= 2c41d8a0cbb --- a/sys/man/1/grep +++ b/sys/man/1/grep @@ -49,6 +49,9 @@ .B -h Do not print file name tags (headers) with output lines. .TP +.B -H +Print file name tags (headers) with output lines, even for a single file. +.TP .B -e The following argument is taken as a .IR pattern . --- a/sys/src/cmd/grep/main.c +++ b/sys/src/cmd/grep/main.c @@ -1,7 +1,7 @@ #define=09EXTERN #include=09"grep.h" -char *validflags =3D "bchiLlnsv"; +char *validflags =3D "bchHiLlnsv"; void usage(void) { @@ -12,8 +12,9 @@ void main(int argc, char *argv[]) { -=09int i, status; +=09int i, h, status; +=09h =3D 0; =09ARGBEGIN { =09default: =09=09if(utfrune(validflags, ARGC()) =3D=3D nil) @@ -38,6 +39,12 @@ =09=09lineno =3D 1; =09=09str2top(filename); =09=09break; +=09case 'h': +=09=09h =3D -1; +=09=09break; +=09case 'H': +=09=09h =3D 1; +=09=09break; =09} ARGEND =09if(flags['f'] =3D=3D 0 && flags['e'] =3D=3D 0) { @@ -57,12 +64,12 @@ =09=09status =3D search(0, 0); =09=09break; =09case 1: -=09=09status =3D search(argv[0], 0); +=09=09status =3D search(argv[0], h > 0 ? Hflag : 0); =09=09break; =09default: =09=09status =3D 0; =09=09for(i=3D0; i