zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.27k stars 1.85k forks source link

zsh-autosuggestions misbehaving #570

Open deprov447 opened 3 years ago

deprov447 commented 3 years ago

Describe the bug

The zsh-autosuggestions is misbehaving. Every-time I start writing a command starting with letter a , the shell suggestion adds some gap between the third and second letter. For example:

To Reproduce

Steps to reproduce the behavior:

Expected behavior

I shouldn't be getting the output shown. I am not able to do stuff this way

Desktop

Additional context

I tried out the commands on Konsole and Guake, Both are misbehaving. But somehow TTYs are good

deprov447 commented 3 years ago

If anyone want to look into my .zshrc : pastebin

kostyay commented 3 years ago

Did you manage to fix this? I have the same problem in mac. In iTerm in JetBrains editor terminal its misbihaving image

deprov447 commented 3 years ago

not really.. I just deleted all zsh configurations and history and all.. reinstalled zsh

But this isnt the solution... just a workaround.

mattseddon commented 3 years ago

You could add the following function to your .zshrc

function remove_from_history () {
    to_remove="${*//\s/\s}"
    LC_ALL=C sed -i '' '/;'"$to_remove"'$/d' "$HISTFILE"
    exec zsh
}

alias rfh=remove_from_history

then run rfh <problematic command> and things should go back to normal (works on MacOS for simple mishaps haven't tested on Linux or with anything as complicated as date -u +%V$(uname)|sha1sum|sed 's/\W//g').

Note: exec zsh can be replaced with src if you use oh-my-zsh and load the zsh_reload plugin at start up in your .zshrc:

plugins=(... zsh_reload)

see here for further details.

Is there a space for something similar to the above in this project? Would it make sense to make this functionality available with this plugin?

You could also add the following to your .zshrc to prevent failed commands getting into your history:

zshaddhistory() { whence ${${(z)1}[1]} >| /dev/null || return 1 }

as per this conversation from the zsh mailing list.

sheanhoxie commented 3 years ago

I have a similar situation where the spaces are removed instead of added.

zsh-autocomplete-error

AckslD commented 3 years ago

@sheanhoxie I think I have the same issue, see #578. It's quite annoying and I haven't found any solution yet :(

ericfreese commented 3 years ago

My guess is that these problems are caused by issues in your prompts. Can you reproduce using simpler prompts?

AckslD commented 3 years ago

@sheanhoxie I solved this with the help of @ericfreese, see #578. Not sure it also solves the original issue by @deprov447 but worth a try.

sheanhoxie commented 3 years ago

@AckslD thanks mate. Looks like it was my right side prompt setup. Once I adjusted that, the issue resolved

jonsmithers commented 3 years ago

Here's a gif of me fighting with this bug.

zsh-autosuggestions-bug

I haven't found a way to reproduce at will from the terminal, but I can reproduce by setting my ~/.zsh_history to:

: 1621973620:0;vim
: 1621973638:0;version=$(git describe --tags)\

(This happens even after I remove right-prompt RPROMPT='')

jonsmithers commented 3 years ago

It was caused by my PROMPT. I changed $fg[cyan] to %{$fg[cyan]%} and the issue stopped.

bbenzikry commented 3 years ago

Just my 2 cents for iTerm users This happened to me with starship prompt and drove me nuts pretty quickly.

I used the following configuration and noticed the issue didn't occur when I removed the emoji / used my own prompt

# starship.toml
[time]
disabled = false
format = 'šŸ•™ [$time]($style) '

Coercing single character width with %G seemed to fix the issue

[time]
disabled = false
format = '%{%GšŸ•™%}  [$time]($style) '

If you see the same symptoms due to character widths ( after making sure LC_ALL and LANG are utf-8), be sure to switch on the following in iTerm profile settings image

qx-775 commented 3 years ago

Can confirm, on starship prompt fixed it with

[character]
success_symbol = '%{%G[āžœ](bold green)%}'
error_symbol = '[āžœ](bold red)'

Thanks for the post above!

qx-775 commented 3 years ago

This issue still sometime pops up randomly when zsh-autosuggestions is on. Example that im seeing

I type kubectl config ge

what I see kubectl config getetontexts

where zsh-autosuggestions suggest kubectl config get-contexts

somehow sometimes zsh-autosuggestions suggests text on starship too soon and it overlaps not sure why Just like the comments above I believe this is a combined issue with starship+zsh-autosuggestions.

bbenzikry commented 3 years ago

This issue still sometime pops up randomly when zsh-autosuggestions is on. Example that im seeing

I type kubectl config ge

what I see kubectl config getetontexts

where zsh-autosuggestions suggest kubectl config get-contexts

somehow sometimes zsh-autosuggestions suggests text on starship too soon and it overlaps not sure why Just like the comments above I believe this is a combined issue with starship+zsh-autosuggestions.

What terminal are you using?

qx-775 commented 3 years ago

I am on Konsole (KDE Plasma terminal). It does not have Unicode 9+ width options or any other unicode size settings.

jonaslsaa commented 2 years ago

I somewhat fixed this on my machine by removing all backslashes () from the end of my lines in _.zshhistory

cycloss commented 2 years ago

It was caused by my PROMPT. I changed $fg[cyan] to %{$fg[cyan]%} and the issue stopped.

This put me on the right track. For me I was using echo -ne "\e]1;$USER@$HOST\a" in the PROMPT to set the terminal window title. I moved it to precmd and the problem disappeared.

jdiegosierra commented 5 months ago

I'm not pretty sure about how to reproduce it, but I think it sometimes happens when using autocompletion and is very annoying

SCR-20240119-jida

orjandesmet commented 3 months ago

It was caused by my PROMPT. I changed $fg[cyan] to %{$fg[cyan]%} and the issue stopped.

I had %{$fg[cyan]%1~%{$reset_color%}, which presented correctly, but missed the closing %} for the fg-color. Changed it to %{$fg[cyan]%}%1~%{$reset_color%} to fix it.

Bran-Tang commented 3 months ago

It was caused by my PROMPT. I changed $fg[cyan] to %{$fg[cyan]%} and the issue stopped.

I have to sign in to comment, bro you are the true hero šŸ‘