zsh-workers
 help / color / mirror / code / Atom feed
From: Johan Grande <nahoj@crans.org>
To: zsh-workers@zsh.org
Subject: [bug] Completion functions _files/_path_files -F filter on escaped file names
Date: Wed, 21 Jun 2023 21:29:39 +0200	[thread overview]
Message-ID: <6bf87a65-1730-8a21-ac5a-d7d05219e024@crans.org> (raw)

Hello maintainers,

I just recently started writing completion functions and I'm bringing to 
you what I think is a bug:

% cat ~/.zshrc
% zsh --version
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

% foo() { echo "$@"; };
% _foo() { local exclusions=('*a *'); _path_files -F exclusions; }
% compdef _foo foo
% touch a 'a a' b
% foo <tab>
a     a\ a  b
% foo '<tab>
a  b

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.

% _foo() { local exclusions=('*a\ *'); _path_files -F exclusions; }
% compdef _foo foo
% foo <tab>
a  b

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

My use case is a tool that works on TagSpaces tags, i.e., 
space-separated tags surrounded by brackets in file names such as 
IMG-2653[vacation alps].jpg. I want to offer, as completion, files that 
have or don't have a certain tag.

Do you think that this behavior could be fixed?

I appreciate the work you do in maintaining zsh which I use as my daily 
shell.

Cheers

-- 
Johan Grande



             reply	other threads:[~2023-06-21 19:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 19:29 Johan Grande [this message]
2023-06-22  3:54 ` Bart Schaefer
2023-06-24 19:55   ` Johan Grande
2023-07-20  5:15     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6bf87a65-1730-8a21-ac5a-d7d05219e024@crans.org \
    --to=nahoj@crans.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).