zsh-users
 help / color / mirror / code / Atom feed
From: Pier Paolo Grassi <pierpaolog@gmail.com>
To: Vin Shelton <acs@alumni.princeton.edu>
Cc: Bart Schaefer <schaefer@brasslantern.com>,
	 Peter Stephenson <p.w.stephenson@ntlworld.com>,
	Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Most Recent File
Date: Sat, 23 Oct 2021 22:56:59 +0200	[thread overview]
Message-ID: <CAP+y1xD0+dQLhK+E8V03q0jzKebKqba==fiYo6V1XT1GVjGj_Q@mail.gmail.com> (raw)
In-Reply-To: <CACeGjnX_oX_79QWtUss4V-A66D=9QY7MF-EikLniaRVm=Tysbg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2186 bytes --]

I think to use it that way you should remove the quoting:

print -lr -- ${(@)f}

and use it like this:

ls "${(f)$recent 3)}"

to have the output of recent to be split at newlines and treated as
separate arguments
would be nice not to have to write all this boilerplate though (I use
global aliases for that)
hope someone will show a better/simpler way

Pier Paolo Grassi


Il giorno sab 23 ott 2021 alle ore 22:44 Vin Shelton <
acs@alumni.princeton.edu> ha scritto:

> Thanks, (I had tried the (q) and the extra assignment after pws suggested
> it) but no luck:
>
> zsh -f
>
> nuc2% function recent {
> function> local dir=
> if [[ $# -gt 2 ]]; then
>   if [[ ! -d "$3" ]]; then
>     print -u2 "$0: directory \"$3\" does not exist."
>     return 1
>   fi
>   [[ $3 != '.' ]] && dir="$3"/
> fi
>
> local f=( ${dir}${~2:-*}(-om[1,${1:-1}]) )
> print -lr -- ${(@q-)f}
> }
> nuc2% recent 3
> zsh
> 'Any Given Sunday.mkv'
> TheEnglishPatient.mkv
> nuc2% \ls -ld $(recent 3)
> ls: cannot access "'Any": No such file or directory
> ls: cannot access 'Given': No such file or directory
> ls: cannot access "Sunday.mkv'": No such file or directory
> -rw-r--r-- 1 acs acs 727146010 Oct 22 15:52  TheEnglishPatient.mkv
> drwxr-xr-x 3 acs acs      3488 Oct 23 12:20  zsh
>
>
> What am I doing wrong?  Does quoting not work correctly in captured output?
>
> I appreciate knowing that printf is builtin; thanks.  Sorry I missed that.
>
>  - Vin
>
>
> On Sat, Oct 23, 2021 at 3:26 PM Bart Schaefer <schaefer@brasslantern.com>
> wrote:
>
>> On Sat, Oct 23, 2021 at 12:08 PM Vin Shelton <acs@alumni.princeton.edu>
>> wrote:
>> >
>> > print -l -- ${dir}${~2:-*}(-om[1,${1:-1}])
>>
>> You're still missing any of the (q) options on those expansions.
>>
>> The easiest thing to do here is something like
>>
>> local recent=( ${dir}${~2:-*}(-om[1,${1:-1}]) )
>> print -lr -- ${(@q-)recent}
>>
>> It's important to add the quoting after any globbing but before you
>> print the result.
>>
>> > Do I really have to use an external command (like `printf') to make
>> this work?
>>
>> printf is a zsh builtin, for some years now.  But as long as you add
>> quoting and do not use echo, you should be OK.
>>
>

[-- Attachment #2: Type: text/html, Size: 6341 bytes --]

  reply	other threads:[~2021-10-23 20:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-23 16:15 Vin Shelton
2021-10-23 16:43 ` Dominik Vogt
2021-10-23 16:58   ` Peter Stephenson
2021-10-23 17:24     ` Dominik Vogt
2021-10-23 17:32       ` Peter Stephenson
2021-10-23 18:39         ` Bart Schaefer
2021-10-23 19:07         ` Vin Shelton
2021-10-23 19:26           ` Bart Schaefer
2021-10-23 20:43             ` Vin Shelton
2021-10-23 20:56               ` Pier Paolo Grassi [this message]
2021-10-23 22:42                 ` Bart Schaefer
2021-10-24  0:24                   ` Pier Paolo Grassi
2021-10-24  0:32                     ` Paul
2021-10-24  1:45                       ` Dominik Vogt
2021-10-24  7:22                         ` Roman Perepelitsa
2021-10-25 19:45                           ` Disabling null elision (was: Re: Most Recent File) Daniel Shahaf
2021-10-25 20:02                             ` Roman Perepelitsa
2021-10-25 20:41                               ` Daniel Shahaf
2021-10-25 21:00                                 ` Ray Andrews
2021-10-25 21:09                                   ` Bart Schaefer
2021-10-25 21:05                                 ` Bart Schaefer
2021-10-25 21:20                                 ` Roman Perepelitsa
2021-10-25 20:05                             ` Bart Schaefer
2021-10-24  1:37                     ` Most Recent File Dominik Vogt
2021-10-23 16:47 ` david rayner
2021-10-23 16:54   ` Vin Shelton
2021-10-23 16:51 ` david rayner

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='CAP+y1xD0+dQLhK+E8V03q0jzKebKqba==fiYo6V1XT1GVjGj_Q@mail.gmail.com' \
    --to=pierpaolog@gmail.com \
    --cc=acs@alumni.princeton.edu \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=schaefer@brasslantern.com \
    --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).