Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How do I find shortest match?
- X-seq: zsh-users 17090
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: How do I find shortest match?
- Date: Thu, 17 May 2012 20:05:03 +0100
- In-reply-to: <r422Ps-1074i-D2378FC62AA34C38A65805B0D3A80DBF@Air>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <r422Ps-1074i-D2378FC62AA34C38A65805B0D3A80DBF@Air>
On Wed, 16 May 2012 15:18:31 -0400
TJ Luoma <luomat@xxxxxxxxx> wrote:
> I don't know what to do in the ??? to compare the filenames and
> choose the shortest one.
sz() { REPLY=${(l.4..0.)${#REPLY}} }
print -l ${^MATCHES}(o+sz[1])
Note you'll need the MATCHES to be the actual path to the file since
glob qualifiers only work on real files.
There's a really nasty trick that doesn't require them to correspond to files, which you'll hate. I think you can combine it into a single expression, but it's bad enough in two.
local min
min=(${${(o)${MATCHES//?/\?}}[1]})
print -l ${MATCHES:#^${~min}}
I'm sure it's completely obvious what this is doing. It's been posted before.
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author