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=-3.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10729 invoked from network); 5 Dec 2022 19:36:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 Dec 2022 19:36:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670268979; b=jCw3Q17Q/l1v8NPu9rAwL7wK4ccdCNbNfHpATR3OCQsI+AbuifCtVY/Me2lur30x3jeuEnA0On jY3Q14vDULZTpwvYwbo59/kzcKLxugfuKWPmJoXbawf2/bczCDwLtT+mmJZaI0DtVnjVcBBCxJ bMc3Zkl29y86OnrBvLMaHbgoDPYd38yUnowYmZWxlLmsS+E19tt9mU+UF1Q14ReD9aTWJ7/YIz TlCKAI3H+aGsLoi/KKsXXSdCp7fFyQ9jNQBRwtQwJeysD4MJdSr5Bs1r7JNW5Ob5bLPazRUeOs M/0FhcJVK9WiQyjft/nuqtctURE9E6xDMWcSAe9NyyYfbg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; 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=1670268979; bh=UFjl/LJSp6uv80DOr78BJmKvRBAmZX5LxVW4eA6rg3Q=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:DKIM-Signature; b=nJwUGWWztyvFgWilcgemA9ygoeaQuDtvQYq/Ede76oQrSzH+E54YFyKA3x6bG0ClSsSwPWZDrQ MYCbEWTG13Wf9H1sYVhHK4PaD+3xBiCCjg+GUQemgsgje9HMQPoZc497YZodaL52o9Q3CcjiWb k7egnyh/lam7x2Skcl2taUtoJXikVFGI6hETAKLSDUZI0Tuv5qJQpoPMQsJsDUj0asAiuLTVje +W+K2rwPiRCW86tg2Yhljv48F5fPlBac0J1l8NK7VCvruDbWehr0uckGYV27aalnAsLcr4p8ls krYOcZqXKQF0RryCr+IGp2n81fcvyVR1XyVXltrm6ZfDtg==; 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-transfer-encoding: Content-type:In-reply-to:From:References:To:Subject:MIME-version:Date: Message-id:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=c702/a3Weq2svYFyE+THvwYuDPjaV/bFoDoHFsQ45MQ=; b=h8O6guZweFF3sqtUR8z2GdAXLW QH1eJNbf1OdKM2ybxol/aLb9XovmRx/kHU89BIJSttfS0ypWwmnTl2zwuBn85WE2jhmvYxl1wafvU FyhjTlpZKO1gW85CiLLsoUkbhVpUtinvM/k7eCHNEHh0MoTcs3ulT0SfbNXDJOKkBPRyrFAsgBPHD 4g6c86k0w1Z4XxSFqFPCeE9rbXH9EKGYpUXagqeFsdHAXs75TfMlQsAjM7kGylTCgInrVAj3Tkqj6 zNexpmcMYu70xlUlnNJbGtdeUz5nScpMlmIs64y7bJHR5bOJAiriyccfqK1QGL3SANewvchiQF6RW 748GcP+g==; Received: by zero.zsh.org with local id 1p2HGE-000LCH-AB; Mon, 05 Dec 2022 19:36:18 +0000 Authentication-Results: zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none Received: from mta02.eastlink.ca ([24.224.136.13]:42738) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1p2HFP-000KVn-5s; Mon, 05 Dec 2022 19:35:27 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta02.eastlink.ca (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) with ESMTPS id <0RMF00NDYES0F420@mta02.eastlink.ca> for zsh-users@zsh.org; Mon, 05 Dec 2022 15:35:25 -0400 (AST) Received: from [192.168.0.4] ([24.207.18.108]) by Eastlink with ESMTPSA id 2HFMp6JivEN8v2HFNpdSuv; Mon, 05 Dec 2022 15:35:25 -0400 X-Authority-Analysis: v=2.4 cv=IPDESCjG c=1 sm=1 tr=0 ts=638e47fd a=xN66ZtSbq5jdJYpBp7G/jQ==:117 a=xN66ZtSbq5jdJYpBp7G/jQ==:17 a=IkcTkHD0fZMA:10 a=tHoAaQYAYbJhNctlfK4A:9 a=QEXdDO2ut3YA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeggdduvdekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptfgrhicutehnughrvgifshcuoehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgeqnecuggftrfgrthhtvghrnhepiedtjeffvefgtdehgefgteekueeggeeitedutddvvdduteetffdvveelgfeukedunecukfhppedvgedrvddtjedrudekrddutdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrddukedruddtkedphhgvlhhopegludelvddrudeikedrtddrgegnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Message-id: <819c9630-f315-8b1c-cb52-3d3ae8de2d5c@eastlink.ca> Date: Mon, 5 Dec 2022 11:35:24 -0800 MIME-version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: The elements of enlightenment Content-language: en-US To: zsh-users@zsh.org References: <54bcd6dd-e589-4696-f042-1155b78df9d2@eastlink.ca> From: Ray Andrews In-reply-to: Content-type: text/plain; charset=UTF-8; format=flowed Content-transfer-encoding: 8bit X-Seq: 28486 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 2022-12-05 08:24, Roman Perepelitsa wrote: > This is the standard way of splitting the output of a command into > lines and dropping empty lines: > > list=( ${(f)"$(setopt)"} ) > The thing is I finally really understand it.  I thought newlines always broke elements.  I thought that what you saw was what you had. > () { > local k v > local -A color=(on 32 off 33) > for k v in ${(kv)options}; do > printf '%-20s = \e[%sm%s\e[0m\n' $k ${color[$v]} $v > done > } That's most educational, I had no idea you could do that 'for k v in' double capture.  And that's a cool demonstration of the use of an associative array -- the name can be called by a variable. Powerful.  But, since setopt is a builtin anyway, why not just use it as is?  I love replacing binaries with native zsh code, but setopt is part of the family anyway so why not just take it's output?  The function I'm playing with requires the array as I have it, just getting the printout isn't enough.  I tweaked your code like this: local k v local list=() local -A color=(on ${red} off ${nrm})        # My color variables do the predictable thing.     for k v in ${(kv)options}; do         list+=$( printf '%-20s %s%s\e[0m\n' $k ${color[$v]} $v )     done ... to get my list.  The equivalent as I now have it is: local list=( "$( setopt )" ) list=( ${(f)list} ) list=( "${list[@]/ off/${red} off${nrm}}" )    # red = 'off' here cuz that's the way Sebastian had it. Which is best?  Probably hardly matters, but still, it's good to know.  printf is heavy, no?  setopt might be lighter?