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

Enable fuzzy completions for complete --do-complete? #5467

faho opened this issue Jan 2, 2019 · 3 comments

Enable fuzzy completions for complete --do-complete? #5467

faho opened this issue Jan 2, 2019 · 3 comments


Copy link

faho commented Jan 2, 2019

As mentioned by @foonathan on gitter:

I have a string like /u/b and I want to do the path completion to /usr/bin fish does when pressing . But I am writing a script, so I can't press tab. Is there a way to trigger a completion on a string programmatically?


I've tried complete -C"echo /u" which gives /usr, but complete -C"echo /u/b" doesn't return anything (fish 2.7.1)

This is because complete --do-complete only uses COMPLETION_REQUEST_DEFAULT.

If we changed

complete(do_complete_param, &comp, COMPLETION_REQUEST_DEFAULT);



It would give fuzzy completions. I believe that would improve the situation in most cases where we currently use it, but if anything is assuming that it's always going to be a prefix (not even a substring) it might break.

Alternatively, we could add another flag that enables fuzzy completions, but it's probably a better default to do them.

Copy link

mqudsi commented Jan 3, 2019

I think this would break completion scripts that use complete -C internally and have an alternate path if there were no results (I'm not sure if we have any that do so), as that path won't be taken anymore but fish's cpp autocomplete engine expects that completions returning from completion scripts are strict supersets of the original string and will disregard any that don't strictly match the existing contents.

Copy link
Member Author

faho commented Jan 3, 2019

have an alternate path if there were no results

It's still possible to not get any results!

The scripts can't

  • assume that the results all have the searchstring as prefix

  • assume that there's a certain set of results

Searching for complete -C in share/ ("--do-complete" appears to be unused) shows these results (after filtering out some in comments or documentation):

./completions/ -c scp -d Remote -n "__fish_no_scp_remote_specified; and not string match -e : (commandline -ct)" -a "(complete -C'ssh ' | string replace -r '\t.*' ':')"
./completions/ -r -c su -s c -l command -d "Pass command to shell" -xa "(complete -C(commandline -ct))"
./completions/ -c which -a "(complete -C(commandline -ct))" -x
./completions/    complete -C"$args"
./completions/    complete -C"$args"
./completions/ -c xterm -s e -a "(complete -C(commandline -ct))" -x -d 'Run program in xterm'
./completions/    _svn_cmpl_ $cmd -l diff3-cmd -d 'Use as merge command' -xa "(complete -C(commandline -ct))"
./completions/    _svn_cmpl_ $cmd -l diff-cmd -d 'Use external diff command' -xa "(complete -C(commandline -ct))"
./completions/        complete -C"$argv"
./completions/ -c type -a "(complete -C(commandline -ct))" -x
./functions/            printf '%s\n' $ctoken[1]=(complete -C$ctoken[2])
./functions/            complete -C$ctoken
./functions/        printf "%s\n" file://(complete -C"echo $stripped")
./functions/    complete -C"$diff $args $token"
./functions/    printf "%s\n" (complete -C$res)

Uses like complete -C'ssh ' are safe, because the token is empty so it won't fuzzy-match anyway.

Uses like for which, complete -C(commandline -ct) are okay because they want to complete like we do normally, which is with fuzzy matches. That also applies to sudo, doas, env, type et al.

So that leaves three of the four functions, and any external users.

Copy link
Member Author

faho commented Mar 12, 2019

Looking at it a bit more closely, all of those functions are for completion, which again means that they want to complete. So I'm enabling this now to see if we get any complaints.

@faho faho closed this as completed in ecfe4ac Mar 12, 2019
@faho faho removed this from the fish-future milestone Mar 12, 2019
@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.
None yet

No branches or pull requests

2 participants