zsh-workers
 help / color / mirror / code / Atom feed
* _files -g <pattern> offers files that don't match the pattern and conversely
@ 2023-07-15 13:31 Johan Grande
  2023-07-15 13:34 ` Johan Grande
  2023-07-15 16:16 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Johan Grande @ 2023-07-15 13:31 UTC (permalink / raw)
  To: zsh-workers

Are these bugs or am I misunderstanding how the -g option works?

With zsh 5.8.1 (x86_64-ubuntu-linux-gnu) and an empty .zshrc.

% ls
a  b

% _f() { _files -g 'c(.)' }; compdef _f f
% f <tab>
a  b       # even though 'a' and 'b' don't match the pattern

However,

% _f() { _path_files -g 'c(.)' }; compdef _f f
% f <tab>  # nothing

Conversely,

% _f() { _files -g '^(a #)(.)' }; compdef _f f
% f <tab>  # nothing, even though 'b' matches the pattern

However,

% _f() { _path_files -g '^(a #)(.)' }; compdef _f f
% f <tab>  # becomes
% f b

Also, and this is the same for _files and _path_files:

% f() { echo $@ }
% _f() { _files -g 'c' }; compdef _f f
% f <tab>  # becomes
% f c      # even though there is no such file

-- 
Johan Grande


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: _files -g <pattern> offers files that don't match the pattern and conversely
  2023-07-15 13:31 _files -g <pattern> offers files that don't match the pattern and conversely Johan Grande
@ 2023-07-15 13:34 ` Johan Grande
  2023-07-15 16:16 ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Johan Grande @ 2023-07-15 13:34 UTC (permalink / raw)
  To: zsh-workers

Apologies, this line should go at the top:

> % f() { echo $@ }



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: _files -g <pattern> offers files that don't match the pattern and conversely
  2023-07-15 13:31 _files -g <pattern> offers files that don't match the pattern and conversely Johan Grande
  2023-07-15 13:34 ` Johan Grande
@ 2023-07-15 16:16 ` Bart Schaefer
  2023-07-15 16:51   ` Johan Grande
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2023-07-15 16:16 UTC (permalink / raw)
  To: Johan Grande; +Cc: zsh-workers

On Sat, Jul 15, 2023 at 6:32 AM Johan Grande <nahoj@crans.org> wrote:
>
> % _f() { _files -g 'c(.)' }; compdef _f f
> % f <tab>
> a  b       # even though 'a' and 'b' don't match the pattern

The only way I can make this happen is if "a" and "b" are directories.
_files will complete local directory names if there are no matching
files.

> % _f() { _path_files -g 'c(.)' }; compdef _f f
> % f <tab>  # nothing

_path_files expects the pattern to match directories too.

> % _f() { _files -g '^(a #)(.)' }; compdef _f f
> % f <tab>  # nothing, even though 'b' matches the pattern

The space in the pattern needs to be quoted, it's being taken as a
word separator.

_f() { _files -g '^(a\ #)(.)' }

I haven't investigated possible fixes.

> % _f() { _path_files -g '^(a #)(.)' }; compdef _f f
> % f <tab>  # becomes
> % f b

Unlike _files, _path_files is applying the pattern directly and
doesn't have a problem with the space.

> Also, and this is the same for _files and _path_files:
>
> % f() { echo $@ }
> % _f() { _files -g 'c' }; compdef _f f
> % f <tab>  # becomes
> % f c      # even though there is no such file

There's only one possible completion, so it's offered.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: _files -g <pattern> offers files that don't match the pattern and conversely
  2023-07-15 16:16 ` Bart Schaefer
@ 2023-07-15 16:51   ` Johan Grande
  2023-07-15 21:28     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Grande @ 2023-07-15 16:51 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

Le 15/07/2023 à 18:16, Bart Schaefer a écrit :
> On Sat, Jul 15, 2023 at 6:32 AM Johan Grande <nahoj@crans.org> wrote:
>>
>> % _f() { _files -g 'c(.)' }; compdef _f f
>> % f <tab>
>> a  b       # even though 'a' and 'b' don't match the pattern
> 
> The only way I can make this happen is if "a" and "b" are directories.
> _files will complete local directory names if there are no matching
> files.

In my test they are regular files, but the problem disappears if I 
replace /usr/share/zsh/functions/Completion/ with that of zsh 5.9, so it 
seems that this one was fixed.

>> [...]
>> % _f() { _files -g 'c' }; compdef _f f
>> % f <tab>  # becomes
>> % f c      # even though there is no such file
> 
> There's only one possible completion, so it's offered.
> 
OK, thank you.

-- 
Johan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: _files -g <pattern> offers files that don't match the pattern and conversely
  2023-07-15 16:51   ` Johan Grande
@ 2023-07-15 21:28     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2023-07-15 21:28 UTC (permalink / raw)
  To: Johan Grande; +Cc: zsh-workers

On Sat, Jul 15, 2023 at 9:51 AM Johan Grande <nahoj@crans.org> wrote:
>
> Le 15/07/2023 à 18:16, Bart Schaefer a écrit :
> > On Sat, Jul 15, 2023 at 6:32 AM Johan Grande <nahoj@crans.org> wrote:
> >>
> >> % _f() { _files -g 'c(.)' }; compdef _f f
> >> % f <tab>
> >> a  b       # even though 'a' and 'b' don't match the pattern
> >
> > The only way I can make this happen is if "a" and "b" are directories.
> > _files will complete local directory names if there are no matching
> > files.
>
> In my test they are regular files

Hmm.  OK, I can now reproduce this with both 5.8 and 5.9 _files but
only if there are no local directories either (e.g., with "a" "b" and
"d/" I get "d" only).

So the real reason here is that _files always tries the "directories"
and "all-files" tags if "globbed-files" doesn't find anything.
_path_files does not use the same tags list.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-15 21:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-15 13:31 _files -g <pattern> offers files that don't match the pattern and conversely Johan Grande
2023-07-15 13:34 ` Johan Grande
2023-07-15 16:16 ` Bart Schaefer
2023-07-15 16:51   ` Johan Grande
2023-07-15 21:28     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).