Zsh wants to autocorrect a command, with an _ before it

Zsh

Zsh Problem Overview


I just started using Zsh lately for some of the integrated support in the shell prompt for my Git status etc.

When I type in:

 ruby -v

to confirm the version of ruby I'm running, Zsh asks if I want to change the command to _ruby. Well after saying no at the prompt and the command completing as expected I continue to get the question at the prompt after confirming my command is correct.

I'm assuming there is a completion file or something of the sort.

Thanks

Update:

The shell is no longer trying to complete _ruby, it stopped responding after closing the shell a few times some how.

I tried to clean the file up several times but there is a "opts" variable that is 50 or more lines long and the lines are all ran together, some lines more than 150 characters. Maybe I could email an attachment to you if you still want to see it. I sincerely apologize for the messy post.

Zsh Solutions


Solution 1 - Zsh

This is command autocorrection, activated by the correct option. It has nothing to do with completion. You're seeing _ruby because zsh thinks there is no ruby command and it offers _ruby as the nearest existing match.

If you've just installed ruby, it's possible that zsh has memorized the list of available command earlier, and it won't always try to see if the command has appeared in between. In that case, run hash -rf. Future zsh sessions won't have this problem since the ruby command already existed when they started.

Sometimes, when you change your PATH, zsh forgets some hashed commands. The option hash_listall helps against this. As above, if you can force zsh to refresh its command cache with hash -rf.

Solution 2 - Zsh

You could make an alias:

alias ruby='nocorrect ruby'

It's what I did when zsh kept asking me if I meant .meteor when I typed meteor because auto-correct is still useful from time to time.

Solution 3 - Zsh

I find the autocorrect feature can get annoying at times. So I do in my ~/.zshrc,

DISABLE_CORRECTION="true"

Solution 4 - Zsh

I had the same problem even when the command is not installed.

I can solve it using the CORRECT_IGNORE variable in my .zshrc

# OPTs to enable
setopt HASH_LIST_ALL
setopt CORRECT
# Zsh variable to determine what to ignore,
# in this case everything starting with _ or . 
CORRECT_IGNORE="[_|.]*"

I hope it helps to you or anyone with this issue

Solution 5 - Zsh

Sometime ago after an update, I got command auto-correction enabled which I don't want. If the same happened to you and you want to revert it, in the ~/.zshrc file you'll have make it:
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="false"

or comment it as per bellow:
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

Solution 6 - Zsh

Just a note, on my zsh (version 5.7.1 on macOS), the DISABLE_CORRECTION didn't work.

I saw in my .zshrc file the following two lines, which I then commented out

setopt CORRECT
setopt CORRECT_ALL

That did it for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoe RyanView Question on Stackoverflow
Solution 1 - ZshGilles 'SO- stop being evil'View Answer on Stackoverflow
Solution 2 - ZshmanafireView Answer on Stackoverflow
Solution 3 - ZshgprasantView Answer on Stackoverflow
Solution 4 - ZshensarmanView Answer on Stackoverflow
Solution 5 - ZshSylvesterAbreuLoretoView Answer on Stackoverflow
Solution 6 - ZshJoergView Answer on Stackoverflow