zsh-autosuggestions
zsh-autosuggestions copied to clipboard
zsh-autosuggestions misbehaving
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 : - When trying to start ark from CLI, the output is :
To Reproduce
Steps to reproduce the behavior:
- Was trying to execute
date -u +%V$(uname)|sha1sum|sed 's/\W//g'
but unfortunately executed :
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
If anyone want to look into my .zshrc : pastebin
Did you manage to fix this?
I have the same problem in mac.
In iTerm in JetBrains editor terminal its misbihaving
not really.. I just deleted all zsh configurations and history and all.. reinstalled zsh
But this isnt the solution... just a workaround.
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.
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
@sheanhoxie I think I have the same issue, see #578. It's quite annoying and I haven't found any solution yet :(
My guess is that these problems are caused by issues in your prompts. Can you reproduce using simpler prompts?
@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 thanks mate. Looks like it was my right side prompt setup. Once I adjusted that, the issue resolved
Here's a gif of me fighting with this 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=''
)
It was caused by my PROMPT
. I changed $fg[cyan]
to %{$fg[cyan]%}
and the issue stopped.
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
Can confirm, on starship prompt fixed it with
[character]
success_symbol = '%{%G[ā](bold green)%}'
error_symbol = '[ā](bold red)'
Thanks for the post above!
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.
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?
I am on Konsole (KDE Plasma terminal). It does not have Unicode 9+ width options or any other unicode size settings.
I somewhat fixed this on my machine by removing all backslashes () from the end of my lines in .zsh_history
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.
I'm not pretty sure about how to reproduce it, but I think it sometimes happens when using autocompletion and is very annoying
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.
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 š