Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative matching algorithms (substring, subsequence, etc.) for completions #568

Closed
xiaq opened this issue Feb 9, 2013 · 6 comments
Closed

Comments

@xiaq
Copy link
Contributor

xiaq commented Feb 9, 2013

Currently fish only supports prefix matching for completions. Consider these use cases:

  1. $ ls
    very-long-prefix-001 very-long-prefix-002 very-long-prefix-003
    

    Substring matching (or more specifically suffix matching) would be useful in the above case.

$ ls
lorem-ipsum lorem-bar foo-ipsum foo-bar

zsh allows you to type l-i<Tab> and get lorem-ipsum. Like everything in zsh you have to do some mysterious configuration; in this case, you declare - as some type of separator valid in completions.

A more realistic example for the above use cases is package names - say you want to complete libreoffice-base, but both libreoffice and base match a lot of packages. However lib-b would almost certainly match libreoffice-base.

Although I found zsh helpful in case 2., there is still a case it doesn't cover - when components are joined without separators. Matching the string user typed as a subsequence can solve this problem. In the case of separator-delimited components, it can be almost as accurate as zsh's method, except that lib-b also matches libreoffice-l10n-br and liaaaab-aaa-b (the latter is invented, sorry).

@ridiculousfish
Copy link
Member

Related to #528

@ridiculousfish
Copy link
Member

Implemented as 908b075

The algorithms we support are (in order of preference):

  1. Exact match - FOOBAR matches FOOBAR
  2. Prefix match - FOO matches FOOBAR
  3. Case insensitive exact match: foobar matches FOOBAR
  4. Case insensitive prefix match - foo matches FOOBAR
  5. Substring match: OOBA matches FOOBAR
  6. Subsequence match: FBR matches FOOBAR

This works for tab completing files and executables, though not yet options.

This was referenced May 25, 2013
@dag
Copy link
Contributor

dag commented Jun 5, 2013

One little thing I've noticed is that if I try to complete a long option argument when fish has no completions for that command, the double hyphens expand to .oh-my-zsh which I happened to have in the same directory!

Perhaps the fuzzy matching could exclude hyphens.

@ghost
Copy link

ghost commented Jun 21, 2013

It may be beneficial to try case-insensitive substring/subsequence matching as well.

ridiculousfish added a commit that referenced this issue Sep 15, 2013
@ridiculousfish
Copy link
Member

95d5e55 addresses dag's issue by disabling fuzzy matching for file completions if the argument begins with a dash.

@krader1961
Copy link
Contributor

It seems to me this has been addressed so closing.

@faho faho removed this from the fish-future milestone Apr 10, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants