From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 2B75220922 for ; Sun, 21 Apr 2024 00:55:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Subject:To:From:Date: References:In-Reply-To:Message-Id:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Dlu+RU5X7pHSXnvR2vG2HcCOJ8ikWL2xA7R0lDeGuPk=; b=BNt2JPp7fZiIisK03eb+JB0M3u vZF3WX7LGYau4WkY80y7U5XLFgNlfFv+imOrTaayr1C844QtjTrWBBqD+YsW5He5Ju6/TfZMYivd4 F9X0Xz1qpQPCoZttxGZRd+pkeB3sUSy7eumrFy8nQSknAC5q+5L4ykA7Z/0fPME8h8zZdQAxTlwFV A4hvylmGfjf0xwqZ4eX8mOJOlVAtJAt+iD5lNt+z+j+tG2Ri3Y1GFehPjlTWcFINgXQrObRZ48kpv 4SrjfSVPC1RQHiwQpfrGCaDRZtPB/psa+pnthLMlEmLoPfDXXm1/1YTyc9qyrtpLF/eWwm4OknZnE uetx/8cQ==; Received: by zero.zsh.org with local id 1ryJcG-000DAn-U1; Sat, 20 Apr 2024 22:55:29 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1ryJbS-000CUe-HC; Sat, 20 Apr 2024 22:54:39 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 5989F1200032 for ; Sat, 20 Apr 2024 18:54:36 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Sat, 20 Apr 2024 18:54:36 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekhedgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsehttd ertderreejnecuhfhrohhmpefnrgifrhgvnhgtvgcugggvlhojiihquhgviicuoehlrghr rhihvhesiihshhdrohhrgheqnecuggftrfgrthhtvghrnhepieelveehfefghfffieehtd eigedvgfekffetjefgteeltdeivdeivdetueekgeeknecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhihvodhmvghsmhhtphgruhhthh hpvghrshhonhgrlhhithihqdduudehudekjeejtdegqdduudelvdejfeekhedqlhgrrhhr hihvpeepiihshhdrohhrghesfhgrshhtmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 075A231A0065; Sat, 20 Apr 2024 18:54:36 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-379-gabd37849b7-fm-20240408.001-gabd37849 MIME-Version: 1.0 Message-Id: <8947389c-2243-4b83-b59e-3535c6201228@app.fastmail.com> In-Reply-To: <3d15311d-b5fa-4a55-a17e-e61fcdded7d0@eastlink.ca> References: <53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca> <3d15311d-b5fa-4a55-a17e-e61fcdded7d0@eastlink.ca> Date: Sat, 20 Apr 2024 18:54:15 -0400 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: zsh-users@zsh.org Subject: Re: optimal expansions? Content-Type: text/plain X-Seq: 29844 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sat, Apr 20, 2024, at 10:23 AM, Ray Andrews wrote: > ... this line is Basque to me. It works but I have no idea how. > Anyway that's for me to research. It baffles me that there's color > codes in there. >> print -P "%B%2F${pkg//\%/%%}%f%b" >> fi The "-P" option tells "print" to interpret prompt escapes like "%B" and "%F" (see zshmisc(1)), allowing you to avoid hardcoding ECMA-48 escape sequences. The "${pkg//\%/%%}" expansion interpolates the package name with all "%" characters escaped. > Seems we want '-r' most of the time. Yes, unless you actually do want "print" to interpret substrings like "\n". Sometimes you do, sometimes you don't. If the operands are dynamic and not under your control, you generally don't. > Now that I know not to use newlines for splitting. And of > course that obviates most of my '(@f)'s too. That's because Roman's solution uses "read" to stream the output from "apt-file" instead of saving it all and postprocessing it. This doesn't have anything to do with "print" though. > But I'm betting your code will be faster. If speed is a concern... % cat af_awk #!/bin/sh - apt-file search -- "$1" | awk ' BEGIN { fg_bld_grn = "\33[1;32m" reset = "\33[0m" } $1 != last_pkg { last_pkg = $1 printf "\n%s%s%s\n", fg_bld_grn, $1, reset } { # Preserve runs of blanks in paths. print substr($0, 1 + index($0, " ")) } END { # Lack of input implies that apt-file failed. exit !NR } ' % apt-file search .txt | wc -l 138962 % for x in ray roman awk; do eval time ./af_$x .txt; done >/dev/null ./af_ray .txt 39.43s user 1.74s system 102% cpu 40.099 total ./af_roman .txt 12.99s user 24.97s system 130% cpu 29.069 total ./af_awk .txt 3.08s user 1.02s system 131% cpu 3.131 total -- vq