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

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.

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.

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.

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

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

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"

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.

Related

Zsh (Wsl) can not response when cd command into the specified directory

I have the problem about zsh (wsl) in windows 11, when I cd into the specified directory, only that folder, my zsh doesn't response, and I have to ctrl+c every time I want to type the next command. I don't know what this problem is, and how to fix this. My PowerShell still works normally, only zsh encounters this error. Anyone can help me pls?
I try waiting some minutes and this evently responses, this folder is my repo git in windows, i use zsh to cd into this, and it takes me quite lots of time to enter this folder. How to fix this problem?
I found out in many webs to look for any solution to fix or improve this problem, and i evently also found 2 ways for this.
First, change the line "disable_untracked_files_dirty" into true in your .zshrc file.
Second, if you're using powerlevel10k, add this line "typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet" into the .p10k.zsh file if you're using this file to config your powerlevel10k, or add this line "POWERLEVEL9K_INSTANT_PROMPT=quiet" into your .zshrc file if you're using .zshrc to config your powerlevel10k.
Hope to help

Deleting a command from zsh history

I'm writing a shell history application, and I'm experiencing issues with deleting a command from zsh history. When I was developing bash compatibility, I used readline to manipulate history - I first deleted command from readline's history, then wrote the history to a file. After the program exits, if the history was manipulated, then I do history -r and I get the expected behavior. Since zsh does not use readline and its history command significantly differs from the one that can be found on bash, I'm left with no other choice but to manipulate the history file directly. However, when I do that, the changes are not reflected until the shell is restarted. I have tried to use zsh's equivalent of history -r, which is supposed to be fc -R, but I did not get the expected results. While the command gets deleted from history after running that, pressing the up arrow (in order to go back to the previous command, which should be the one that invoked the program) brings me to a seemingly random command in the history.
I'd appreciate it if someone explained the odd behavior I'm experiencing. Any pointers in the right direction are also welcome.
I have solved this problem in my Zsh history editing plugin zsh-hist by not touching the histfile directly, but instead doing everything through Zsh's own mechanisms:
Set $HISTORY_IGNORE locally to a pattern that matches the contents of the entries you want to delete.
Use fc -W to write the history to file. Because of HISTORY_IGNORE, the unwanted entries will not be written.
Use fc -p to create a new history from file.
Zsh documentation:
$HISTORY_IGNORE parameter
fc builtin command

Tmux asks for root password on every command

I recently had to reinstall my system and ever since I've been having a weird issue with tmux where it prompts me for my sudo password every time it creates a new pane or window (including when I first start it). It appears to make absolutely no difference whether I actually enter it or not; because the prompt happens after the pane/window was already created, I can just Ctrl-C out of the prompt if I want. I’m not sure if more functions are also affected which I just don't use but at least some of those I do use are definitely not (e.g. source-file).
On a sidenote, I also noted that since I changed my login shell to zsh after the reinstall, alias definitions in .zprofile do not carry over to interactive shells anymore, which they definitely did do under my previous system (although the file is definitely sourced as environment variables are set correctly even in the interactive shell). Maybe my shell environment got messed somehow and the tmux problem is just a side-effect of that?
Never mind, I found the issue: I was using a sudo call to start a daemon in my .zprofile, so when the interactive shell sourced that it caused a sudo prompt. I found a workaround which doesn't require sudo which solved the problem.

Weird behaviour with zsh PATH

I just encourage a weird problem with zsh today.
My environment is Mac OS X Yosemite, zsh 5.0.5 (x86_64-apple-darwin14.0)
In .zshrc, I have manually set the PATH variable to something like
export PATH="$PATH:~/.composer/vendor/bin"
Try echo $PATH in terminal, the result is as expected (contained ~/.composer/vendor/bin). Then try executing a binary from ~/.composer/vendor/bin, It'll always return me "zsh: command not found" error.
Try switching to bash, echo $PATH is also as expected, have the same result as zsh shell.
Try executing a binary from ~/.composer/vendor/bin, no problem found. Seem the PATH var is acting well on the bash shell.
What's wrong with my zsh shell?
Thanks
Try using $HOME instead of ~. In many situations, shells do not expand ~ when you expect them to and it is usually better to use $HOME. ~ is really only intended to be a short cut for interactive use. (The only case I can recall where ~ was preferred was in a .gitalias, where ~ was expanded and variables were not.)
Type rehash to pick-up $PATH changes.
From the zsh user guide:
The way commands are stored has other consequences. In particular, zsh
won't look for a new command if it already knows where to find one. If
I put a new ls command in /usr/local/bin in the above example, zsh
would continue to use /bin/ls (assuming it had already been found). To
fix this, there is the command rehash, which actually empties the
command hash table, so that finding commands starts again from
scratch. Users of csh may remember having to type rehash quite a lot
with new commands: it's not so bad in zsh, because if no command was
already hashed, or the existing one disappeared, zsh will
automatically scan the path again; furthermore, zsh performs a rehash
of its own accord if $path is altered. So adding a new duplicate
command somewhere towards the head of $path is the main reason for
needing rehash.
EDIT However #WilliamPursell could be onto something with his comment:
note that "composer" != ".composer"

What makes Ctrl+Q work in zsh

I'm a zsh user who started off with a plain oh-my-zsh configuration and now I try to learn zsh by importing the parts I care about from oh-my-zsh into my own .zshrc and then completely remove oh-my-zsh.
When I now finally went cold turkey and removed oh-my-zsh I noticed that one of my most used shortcuts, Ctrl+Q has stopped working. I've investigated this and found the command to be called push-line according to this source.
I have no idea how to start using that ZLE feature though. I'm not even sure how to check if zle is running or not. I tried for hours to try to search the oh-my-zsh repository, but haven't found the command that activates push-line.
What do I need to do to get Ctrl+Q working? What is it that oh-my-zsh does that I need to put in my own zshrc?
Although I've never used the push-line feature, don't know what it does, and am afraid to even try to find out what "oh my zsh" means, any use of Ctrl+Q is likely to require unbinding it from the tty START function.
STOP (freeze output to the terminal) is normally Ctrl+S and START (unfreeze) is normally Ctrl+Q. To remove those special characters,
stty start '^-' stop '^-'
One can also do
unsetopt flow_control
See: http://www.cs.elte.hu/zsh-manual/zsh_16.html

Resources