From: Ray Andrews <rayandrews@eastlink.ca>
To: Zsh Users <zsh-users@zsh.org>
Subject: optimal expansions?
Date: Fri, 19 Apr 2024 12:22:00 -0700 [thread overview]
Message-ID: <53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca> (raw)
[-- Attachment #1: Type: text/plain, Size: 1466 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 1993 bytes --]
next reply other threads:[~2024-04-19 19:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 19:22 Ray Andrews [this message]
2024-04-19 20:40 ` Lawrence Velázquez
2024-04-19 23:25 ` Ray Andrews
2024-04-20 7:42 ` Roman Perepelitsa
2024-04-20 14:23 ` Ray Andrews
2024-04-20 22:54 ` Lawrence Velázquez
2024-04-20 23:59 ` Ray Andrews
2024-04-21 12:23 ` Roman Perepelitsa
2024-04-21 14:09 ` Ray Andrews
2024-04-21 14:19 ` Roman Perepelitsa
2024-04-21 16:14 ` Stephane Chazelas
2024-04-21 17:39 ` Roman Perepelitsa
2024-04-21 20:13 ` Stephane Chazelas
2024-04-21 20:46 ` Lawrence Velázquez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca \
--to=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).