Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Most Recent File



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