zsh-users
 help / color / mirror / code / Atom feed
* optimal expansions?
@ 2024-04-19 19:22 Ray Andrews
  2024-04-19 20:40 ` Lawrence Velázquez
  2024-04-20  7:42 ` Roman Perepelitsa
  0 siblings, 2 replies; 14+ messages in thread
From: Ray Andrews @ 2024-04-19 19:22 UTC (permalink / raw)
  To: Zsh Users

[-- 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 --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-04-21 20:47 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 19:22 optimal expansions? Ray Andrews
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

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).