Re: [ -d (#i)Temp ]

Ray Andrews <[email protected]> Fri, 10 Apr 2026 12:10:50 -0700
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <[email protected]>

On 2026-04-10 11:19, Roman Perepelitsa wrote:
> This one has a bug that triggers when there is more than one match for
> (#i)Temp and not all matches are directories. The following does not
> have this issue:
>
> [[ -n ''(#i)Temp(#qN/) ]] && echo "there is at least one (#i)Temp dir"
>
>
2 /aWorking/Zsh/Source/Wk 3 % rm -r temp

2 /aWorking/Zsh/Source/Wk 3 % touch temp

2 /aWorking/Zsh/Source/Wk 3 % [[ -d ''(#i)temp(#qN) ]] && echo "it's a 
directory"

2 /aWorking/Zsh/Source/Wk 3 % [[ -n ''(#i)Temp(#qN/) ]] && echo "there 
is at least one (#i)Temp dir"
there is at least one (#i)Temp dir

... Very slick.  I can have a matching *file* but it ignores that and 
captures the directory.

... But,  I want it to fail if there's more than one directory match:

2 /aWorking/Zsh/Source/Wk 3 % md tEMP # Torture testing.

2 /aWorking/Zsh/Source/Wk 3 % [[ -n ''(#i)Temp(#qN/) ]] && echo "there 
is at least one (#i)Temp dir"
there is at least one (#i)Temp dir  # I'd want it to fail here.

2 /aWorking/Zsh/Source/Wk 3 % [[ -d ''(#i)temp(#qN) ]] && echo "it's a 
directory"

... so your original is safer.  It would be tempting the Gods to to want 
it to only accept one possible directory but ignore matching files.

The basic idea is that my wrapper will show the contents of a directory 
if there is a single match:

2 /aWorking/Zsh/Source/Wk 3 % l Temp  # There's only one match so 
directory contents:

CONTENTS of "Temp": All file types, Implied Sensitive. Sorting oldest on 
top by modification time:

  0 [26-04-10--10:17] garbage

Items found: 1
Total bytes in directory "/aWorking/Zsh/Source/Wk/Temp": 4.0K
Total including subdirs: 4.0K

... but when there's more than one match, show a normal 'local' listing:

2 /aWorking/Zsh/Source/Wk 3 % try l && l ,v temp
Sourcing l

  4096 [26-04-10--10:17] Temp/
  4096 [26-04-10--11:39] tEMP/
     0 [26-04-10--11:35] temp

... two directories and one file.

But, it occurred to me that the directory search could be case 
insensitive as desired.  But there must only be only one unambiguous 
match, as before.  And the thing should abort if there's any matching 
files cuz then you'd not have the 'local' listing which is what would 
normally be wanted.  Come to think of it, this might be a bad idea.  
Yup, I'll leave it as it is -- one exact match or bust.

But I'll save your code, that's to be stored for a future day.