From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: optimal expansions?
Date: Sat, 20 Apr 2024 07:23:44 -0700 [thread overview]
Message-ID: <3d15311d-b5fa-4a55-a17e-e61fcdded7d0@eastlink.ca> (raw)
In-Reply-To: <CAN=4vMqfcxt-C-g=4Sk13Qu28LFK46QCfXajhHfFMzLCcsXysg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]
On 2024-04-20 00:42, Roman Perepelitsa wrote:
Hafta start using lines like this all the time. You guys never start a
function without one of these 'emulate' instructions -- make sure that
the func has the environment it needs.
> emulate zsh -o no_unset -o pipe_fail -o err_exit
> () {
> local last_pkg pkg file
So you break it into words automatically here, and any spaced filenames
end up in 'file' anyway!
> apt-file search "$1" | while read -r pkg file; do
> if [[ $pkg != $last_pkg ]]; then
> [[ -n $last_pkg ]] && print
> last_pkg=$pkg
... 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
Seems we want '-r' most of the time. And the '--' should always be
there. Now that I know not to use newlines for splitting. And of
course that obviates most of my '(@f)'s too.
> print -r -- $file
> done
> } "$@"
>
> This implementation fixes a couple of bugs in addition to those
> mentioned by Lawrence: it gets rid of the empty line at start of the
> output, and leaves whitespace in file names unchanged.
To pick nits I want the leading empty line. But I'm betting your code
will be faster. I'll keep Lawrence's edits until such times as I
understand that 'print -P' tho.
[-- Attachment #2: Type: text/html, Size: 2455 bytes --]
next prev parent reply other threads:[~2024-04-20 14:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 19:22 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 [this message]
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=3d15311d-b5fa-4a55-a17e-e61fcdded7d0@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).