fish-shell / fish-shell

The user-friendly command line shell.

Home Page:https://fishshell.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make autocomplete able to correct typos

piekay opened this issue · comments

I recently moved from zsh to fish. While I love fish, there is one thing that bugs me: I move around a lot between keyboards (and spoken languages), so it happens way too often, that I forget a letter or capitalize the second char of a folder.

I know that a similar discussion happened in the past to specifically reimplement zsh autocorrection, which I agree makes no sense.

My idea would be to add a very simple checker to check if there is a program / folder within a n letter radius and then add that option to the autocorrect, allowing a user to select those too.

I am not very experienced with the fish codebase, but I would help to the best of my abilities if this is a feature that other users, contributors and members would like to see.

then add that option to the autocorrect

Do you mean add that as a completion option? Because we already do (unless there is a match for the argument as currently entered). If not, well, we don't have "an autocorrect".

Can you be more specific and provide a reproducible case with step-by-step what your environment contains, what you type in, and at what point you want what to show what?

A simple example would be:

typing cd Dekt

and then pressing Tab to trigger completion. Currently fish doesn't react to that at all. It would be nice, if fish could recommend Desktop anyways.

This could be solved by both adding the current String and the “corrected“ String to the autocompletion, to allow a user to easily switch between what was typed and what the algorithm thinks was meant. Adding what the user typed to the autocomplete menu fixes the common issue with these systems that is that if someone types mkdir -p /user and then presses tab, because they want to create a /userdata/stuff folder it is easy to switch back from /usr to /user

typing cd Dekt

This does trigger completion to cd Desktop for me - there's a fuzzy matching algorithm, noted in #568 (comment)

Triggering the pager when an exact or prefix match is not available would be different, though. I'm not sure that's a better experience (tab twice and enter to accept a substring match?)

typing cd Dekt

This does trigger completion to cd Desktop for me - there's a fuzzy matching algorithm, noted in #568 (comment)

Triggering the pager when an exact or prefix match is not available would be different, though. I'm not sure that's a better experience (tab twice and enter to accept a substring match?)

Oops, I actually messed up the cd Command. Correct would be cd Deks and then pressing tab.

My idea would be to correct it the first time you press tab, but also keep the uncorrected version around, basically offering to correct it to Desktop, while also allowing you to switch back by pressing tab again instead of Escape (for convenience, since the completion would more or less guess in these cases)

This would be doable by using a proper string distance algorithm instead of the current rudimentary typo detection, though it would not keep around both the misspelling and the corrected version and would be without the pager, if I am correctly remembering how the completions machinery currently works.