Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Most Recent File
- X-seq: zsh-users 27281
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Most Recent File
- Date: Sun, 24 Oct 2021 02:37:45 +0100
- Archived-at: <https://zsh.org/users/27281>
- In-reply-to: <CAP+y1xC3Dx74sBaCf8mgmEcOMh+hUH6zAdt236k=JTjw4-cBqQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- References: <20211023164338.GA6763@gmx.de> <095002061dc32afdfb1dcfe51e1171e23e62375d.camel@ntlworld.com> <20211023172445.GA8911@gmx.de> <0b757d10f1a2374d5a84199fbed71314e16fea63.camel@ntlworld.com> <CACeGjnVEN_zXR1xVk=UCOpBh7afAD7+5vGxfBJOkfgOnSa+oyw@mail.gmail.com> <CAH+w=7Ze50aeioPOe5jT0XXSU9eS0=nn18goc8LcdGy_xZSpsw@mail.gmail.com> <CACeGjnX_oX_79QWtUss4V-A66D=9QY7MF-EikLniaRVm=Tysbg@mail.gmail.com> <CAP+y1xD0+dQLhK+E8V03q0jzKebKqba==fiYo6V1XT1GVjGj_Q@mail.gmail.com> <CAH+w=7Zhj_+3jaDQLvx5Y6mCwb0T7QV6x+yygaZm84hacez5cQ@mail.gmail.com> <CAP+y1xC3Dx74sBaCf8mgmEcOMh+hUH6zAdt236k=JTjw4-cBqQ@mail.gmail.com>
- Reply-to: dominik.vogt@xxxxxx
On Sun, Oct 24, 2021 at 02:24:04AM +0200, Pier Paolo Grassi wrote:
> >That doesn't work because if one of the file names has a newline in
> >it, (f) will split it into two words. (Also I think you left out an
> >open paren.)
>
> sorry about that, I haven't ever considered newlines in filenames, since I
> wouldn't put them in the first place.
Maybe just stop putting spaces in filenames. Unix systems are
cluttered with scripts and other programs that cannot handle
whitespace, asterisks, hyphens, semicola and other charaters with
a special shell or program meaning anyway. (The vast majority of
people forget to put variables in double quotes in their scripts.)
Passing funny file names to programs is asking for trouble. In
the worst case it can destroy or compromise your system.
You could try this solution where the most recent entries are
automatically put into an array (needs some work to deal with *
matching nothing):
precmd () { __recent=( *(-om) ) }
$ ls -- "${(@)__recent[1,3]}"
Or if it's only about ls, you could write a function "ls-recent"
that implements the logic.
The suggestions with "eval" or automatic unquoting of values may
be a path to disaster.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
Messages sorted by:
Reverse Date,
Date,
Thread,
Author