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

Re: [bug] Completion functions _files/_path_files -F filter on escaped file names



On Wed, Jun 21, 2023 at 12:29 PM Johan Grande <nahoj@xxxxxxxxx> wrote:
>
> When completion with _files or _path_files is called at the beginning of
> an argument, exclusion patterns given with `-F` are applied to
> already-escaped file names. This breaks patterns that contain escapable
> characters such as a space or [].
>
> With a \ added to the pattern, 'a a' is filtered out.

Upon closer examination, the documentation of the -F option is
imprecise.  -F is a substitute for the "ignored-patterns" zstyle, and
the description of that style clearly states that it filters out trial
completions.  Thus the -F option does not ignore files, it ignores the
strings that are candidates to be inserted on the command line when
completing files.

> But this is very brittle as it depends on the implementation of the
> escaping instead of the file names themselves.

Unfortunately this is implemented in the internals of the "compadd"
builtin and other forms of completion rely on it.

> Do you think that this behavior could be fixed?

We could try this.  However, it's not backward-compatible for people
who are already quoting spaces etc. for _files -F patterns.

diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index d46dcbe5a..c471ad08e 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -100,6 +100,12 @@ if (( $#ignore )); then
   fi
 fi

+# Adjust the patterns for the effects of "compquote" on file names.
+# What's needed here is the inverse of ${(b)...}, that is, quote only
+# characters that are NOT pattern characters but might need quoting.
+# Backslashes appearing in a file name remain a bugaboo here.
+ignore=( ${ignore//(#b)([\!\#\$\&[:space:];\"\'])/\\${match[1]}} )
+
 # If we were given no file selection option, we behave as if we were given
 # a `-f'.




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