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

Re: string match simplification?



What are you trying to do, exactly? I think there's more going on than a simple case of picking the right transformation. If file1="foo" and file2="foo.", then $file1:r == $file2:r and $file1:e == $file2:e, even though $file1 != $file2. That shows that you can't always reconstruct the exact filename given the :r and :e components. 

Even if you decide to keep the dot with the extension, you can't use something like ${extension:+.$extension} to include it only when there's an extension, because both files have empty extensions and will not get a . that way. You still have to deal with the file. case explicitly somehow.

What are your assumptions, and what's the end goal? 
 

On Tue, Sep 3, 2024 at 4:36 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:


On 2024-09-03 12:21, Roman Perepelitsa wrote:

If the input is "foo.", this script will print "filename is: foo." (note the trailing dot). Probably not what you want. If you use :r instead, you'll get the expected "foo" without the trailing dot.

It's a bit subjective but I think I do want the trailing dot.  It's there, so a legitimate part of the filename.  I'm not throwing it away.  But by itself we can hardly call it an extension.  If I used :r and :t:r and then cobbled them back together again the dot would disappear.  So I'm thinking a trailing dot is a null event and if there is an extension the dot goes with the extension -- but that's ... hmmm .... that's not very tight logic, is it? Anyway :r and :t:r loose the dot, so I hafta store it somewhere.


--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author