Skip to content

Option to force completion to escape instead of using quotes #11271

Closed

Description

@antoyo

Hi.
Since the new release, fish will quote completion with special characters instead of escaping them.
This breaks my workflow because I often use completions to then add a wildcard like * (for instance, to diff two files), but this no longer works because now it is quoted (so the wildcard won't be interpreted).
So, please add an option to always force the completion to escape special characters instead of using quotes.

Also, it seems there might be some incoherent behavior here, for instance:

$ touch '[test] file1'
$ ls <Tab> # completes to: ls '[test] file1'
$ touch '[test] file2'
$ ls <Tab><Tab> # completes to: ls \[test\]\ file1

Thanks.

Activity

  1. krobelus commented on Mar 13, 2025

    @krobelus
    Contributor

    Interesting. As demonstrated by your example, backslashes are used when a completion is not unique.
    The idea is to allow use cases like yours (for example ls <Tab>* will result in ls \[test\]\ file* if both files exist).

    But you mention there's also a scenario where a completion is unique but you still want to add *?
    Perhaps to match a file that will be created later?
    I'm trying to imagine your scenario. Hopefully we can improve the heuristic. Feels like it wasn't a strictly improvement. Here's a hack to turn it off:

    diff --git a/src/reader.rs b/src/reader.rs
    index 0808e1bcd1..85b4123856 100644
    --- a/src/reader.rs
    +++ b/src/reader.rs
    @@ -6148,6 +6148,3 @@ pub fn completion_apply_to_command_line(
     
    -    let mut escape_flags = EscapeFlags::empty();
    -    if append_only || trailer.is_none() {
    -        escape_flags.insert(EscapeFlags::NO_QUOTED);
    -    }
    +    let mut escape_flags = EscapeFlags::NO_QUOTED;
         if no_tilde {
  2. antoyo commented on Mar 13, 2025

    @antoyo
    Author

    But you mention there's also a scenario where a completion is unique but you still want to add *?

    No. I do not know how the heuristic works, but there are cases when there are multiple completions, but I want to add *.
    I believe it will use \ when doing <Tab><Tab>, but doing te<Tab><Tab> will use quotes.
    An example if this isn't clear:

    $ touch '[test] file1'
    $ touch '[test] file2'
    $ ls <Tab><Tab> # completes to: ls \[test\]\ file1
    $ ls te<Tab><Tab> # completes to: ls '[test] file1'
  3. krobelus commented on Mar 13, 2025

    @krobelus
    Contributor

    ah I see. Currently we always use quotes if the completion is rewriting the current token (as opposed to appending).
    Even if completion is ambiguous -- which is wrong, at least in the case where two matching completions have a shared prefix

  4. added a commit that references this issue on Mar 14, 2025
    9f79fe1
  5. added
    regressionSomething that used to work, but was broken, especially between releases
    on Mar 15, 2025
  6. added this to the fish 4.0.2 milestone on Mar 15, 2025
  7. added a commit that references this issue on Mar 16, 2025
    ffbf957
  8. locked as resolved and limited conversation to collaborators on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    regressionSomething that used to work, but was broken, especially between releases

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions