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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, 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 59AD8240E3 for ; Fri, 19 Apr 2024 21:22:39 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713554559; b=pqIN4GLQALpCIovij55asKJ+tpWmtW9lTpvdZbWRO6FcOrz0dVbwhasH9PtjLudkDADWUSL+jv 12RBzB5MKYEluu1RN85h8dX6FZXG4KAz3ngcN8NJ/Y7BfCL2Lql3qYP/xvNJ39diboXvVayFsR 1S1MMlzmf1hNXiTm2asMe0a5H5wJV7TqPMWEzvrdp/V5vNIg9Ce+tovO36s604x/ngpOz6B2XA 7DgYC6nQQmcYl8ziqAyzDzHMV5P/pMhlcncmwhn2hHyMuG1YOIzboFZmKXJn0YmO32TXotfNB+ nJgIH9ffbS9/F6F/Zt1ln06GYgVeSYr92SHEYOpef6DykA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713554559; bh=X6EBf8FDZ3IknS+ZgMnZ3xjoqC3VnF84fH1XW4+XbE4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:From:To:MIME-Version:Date:Message-ID:Content-Type: DKIM-Signature; b=m4yllLCXk5PUqlV/Dv6SfOHonkzi3J/Wq77k1K1uwJ2IAik1TY40IDchbcWoJ/HitsGN9E6UsR 76eb98fzBHRJ6TnzQi5rYEP1XlEqOsJEwKydaOKVFaEWUUKyWU+xIpHdKNhdx2l2mI/YJMA5Fu h4Uo5jF9nWvHsqcOuUI23a+INKzMqzFPW/xxWCuHkI+4fSWaB5ewD0kzZXwt83wB+ETEPl4bFK yRiKYvb3LsYLbgoLUO7y5He+AjY1fmsgPkLXZcw3eoB9k4nGv5ShKdeca/F89cC9219LqXk8Eq N46lUVYNeZLTgG0V7Z7TTgMS3NfFbZUFrPdX4Xbs/oz9rg==; 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:Subject:From:To:MIME-version:Date: Message-id:Content-type:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=AjyHX7xFuHi3fUaWsb6iwi2r3QvFiDIjr90SXgZC+4Q=; b=KERVxGTWH9Cb+uVDzpUgpDQRu7 xwejUR5RXf5sM3lqzsmdnsgzBt9GL85sgl8qWw3O3fdkuUkZLrLdBiMQhBGFhgqwC8a2cz5M2k6ce cOcVx7nMKnqxfQvvQIHn2Lamy01f6Hv08aa9SKXPCxZ4ACrJPLCk4JhbhEtfClsWFJoEg1s+4I1O/ 9LWBQvi5+m6+HHF8SPB46FKZyPyWQxVCD3x2vskVjISefb67yiaFy7h4hWyQuHPaYknqogQuZHC5P cAAKKL+nFjqUf2hPMMPdA2Hu5nJm3vE7PxY6ynxIv75sHO7k01g3xVG5bcJiQtf0KxslVyB311Qm0 EwK0+cBQ==; Received: by zero.zsh.org with local id 1rxtol-000FUu-Bl; Fri, 19 Apr 2024 19:22:39 +0000 Authentication-Results: zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none Received: from mta03.eastlink.ca ([24.224.136.9]:37987) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rxtoA-000Eml-E1; Fri, 19 Apr 2024 19:22:02 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta03.eastlink.ca ([24.224.136.9]) with ESMTPS id <0SC71RZX8F4H2QF0@mta03.eastlink.ca> for zsh-users@zsh.org; Fri, 19 Apr 2024 16:22:01 -0300 (ADT) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp01.eastlink.ca ([71.7.199.166]) with ESMTPSA id xto8rDdf2Aimnxto8r4vy5 (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Fri, 19 Apr 2024 16:22:01 -0300 X-Authority-Analysis: v=2.4 cv=Q8Rx4J2a c=1 sm=1 tr=0 ts=6622c459 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=t_gl4qhUCFDD5IK8HyAA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=wl8mkzVvO2Tjkk0aJzUA:9 a=6gDB5_Ue02BzDOUf:21 a=_W_S_7VecoQA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekvddgudeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfgtefuvffnkffpmfdpqfgfvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurheptgfkffggfgfvhffusegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpeeffeeivddtkedvgfetkeevudfhtdeltdegtedttdekieffhfeuhfekheegtdevteenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: -100 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------Zsed3En14HZ35e3Lf0gICqtD" Message-id: <53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca> Date: Fri, 19 Apr 2024 12:22:00 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Content-language: en-US To: Zsh Users From: Ray Andrews Subject: optimal expansions? X-Seq: 29837 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: This is a multi-part message in MIME format. --------------Zsed3En14HZ35e3Lf0gICqtD Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Script:     grn=$'\e[32;1m'     nrm=$'\e[0m'     var=( "${(@f)$(apt-file search $1)}" )     targ=     var2=()     for ((i=1; i<=$#var; i++ )); do         if [[ "$targ" != "${${=var[i]}[1]}" ]]; then             targ="${${=var[i]}[1]}"             var2+="\n${grn}${${=var[i]}[1]}${nrm}" # Copy first word of line.         fi         var2+="${${=var[i]}[2,-1]}" # Copy the rest of the line no matter how many words.     done     print -l "$var2[@]" --------------------------------------------------- That's my preferred way to look at 'apt-file search' output (Debian and derivatives only of course).  It works fine and I think I understand all the expansions and splitting.  One you get used to it the nested expansions aren't so scary, just read them from inside out, one step at a time and it's easy.  But is it optimal?  I've been known to go one step to the right by first going three steps to the left, then four steps to the right.  I'm guessing it's tight, but ... BTW, I had a much simpler way of doing this based on a 'two words per line of output' assumption, but Debian, in their wisdom, have a very few installable files that have spaces in their names, so the above: "   [2,-1]   " way of doing things is needed.  I have to split on lines and then sub-split on words ... I think.  But I do have a talent for making things harder than they need be. --------------Zsed3En14HZ35e3Lf0gICqtD Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Script:

    grn=$'\e[32;1m'
    nrm=$'\e[0m'

    var=( "${(@f)$(apt-file search $1)}" )
    targ=
    var2=()
        
    for ((i=1; i<=$#var; i++ )); do
        if [[ "$targ" != "${${=var[i]}[1]}" ]]; then
            targ="${${=var[i]}[1]}"
            var2+="\n${grn}${${=var[i]}[1]}${nrm}" # Copy first word of line.
        fi
        var2+="${${=var[i]}[2,-1]}" # Copy the rest of the line no matter how many words.
    done
        
    print -l "$var2[@]"

---------------------------------------------------

That's my preferred way to look at 'apt-file search' output (Debian and derivatives only of course).  It works fine and I think I understand all the expansions and splitting.  One you get used to it the nested expansions aren't so scary, just read them from inside out, one step at a time and it's easy.  But is it optimal?  I've been known to go one step to the right by first going three steps to the left, then four steps to the right.  I'm guessing it's tight, but ...

BTW, I had a much simpler way of doing this based on a 'two words per line of output' assumption, but Debian, in their wisdom, have a very few installable files that have spaces in their names, so the above: "   [2,-1]   " way of doing things is needed.  I have to split on lines and then sub-split on words ... I think.  But I do have a talent for making things harder than they need be.


--------------Zsed3En14HZ35e3Lf0gICqtD--