zsh-autosuggestions icon indicating copy to clipboard operation
zsh-autosuggestions copied to clipboard

zsh-autosuggestions misbehaving

Open deprov447 opened this issue 4 years ago ā€¢ 23 comments

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:

  • when if try to write awk -v it outputs me this : image
  • When trying to start ark from CLI, the output is : image

To Reproduce

Steps to reproduce the behavior:

  • Was trying to execute date -u +%V$(uname)|sha1sum|sed 's/\W//g' but unfortunately executed : image

Notice the missing ' and additional \n\n

  • After this the problem started

Expected behavior

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

Desktop

  • OS + distribution: Arch Linux (plasma 5.20.1)
  • Zsh version: 5.8
  • Kernel: Linux 5.4.72-1-lts

Additional context

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

deprov447 avatar Oct 27 '20 13:10 deprov447

If anyone want to look into my .zshrc : pastebin

deprov447 avatar Oct 27 '20 13:10 deprov447

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

kostyay avatar Dec 17 '20 10:12 kostyay

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

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

deprov447 avatar Dec 17 '20 17:12 deprov447

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.

mattseddon avatar Dec 31 '20 07:12 mattseddon

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

  • It seems to happen if I write something out that follows along with a prior command, but once I hit a certain point, a letter is removed and I can continue to type out the command, but now there is either a letter or space missing.
  • If I try to delete back it removes letters as I hit the initial point it failed, but the original missing letter now reappears
  • If I ignore the initial failure and just keep typing, the command will execute successfully as if there were no letters missing

zsh-autocomplete-error

sheanhoxie avatar Jan 18 '21 18:01 sheanhoxie

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

AckslD avatar Jan 19 '21 15:01 AckslD

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

ericfreese avatar Jan 19 '21 17:01 ericfreese

@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.

AckslD avatar Jan 21 '21 11:01 AckslD

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

sheanhoxie avatar Jan 21 '21 17:01 sheanhoxie

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 avatar Jan 30 '21 02:01 jonsmithers

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

jonsmithers avatar Jan 30 '21 23:01 jonsmithers

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

bbenzikry avatar Apr 11 '21 02:04 bbenzikry

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 avatar May 06 '21 23:05 qx-775

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.

qx-775 avatar May 14 '21 14:05 qx-775

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?

bbenzikry avatar May 14 '21 15:05 bbenzikry

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

qx-775 avatar May 14 '21 16:05 qx-775

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

jonaslsaa avatar Apr 27 '22 09:04 jonaslsaa

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.

cycloss avatar Jun 06 '22 08:06 cycloss

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

jdiegosierra avatar Jan 19 '24 09:01 jdiegosierra

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.

orjandesmet avatar Mar 27 '24 12:03 orjandesmet

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 šŸ‘

Bran-Tang avatar Mar 29 '24 05:03 Bran-Tang