zsh-autosuggestions: Segfault after sourcing zshrc again - conflict with zsh-autosuggestions even when sourced in right order.

Hi, this issue is similar to issue #96: After opening zsh and sourcing .zshrc, zsh exits with “zsh: segmentation fault zsh”:

% zsh
% . ~/.zshrc
zsh: segmentation fault  zsh

Issue #96 was solved by sourcing zsh-autosuggestions before zsh-syntax-highlighting, but that solution no longer works. Zsh segfaults no matter their order. Here’s the .zshrc file:

source ~/bin/zsh/antigen/antigen.zsh
antigen bundle tarruda/zsh-autosuggestions
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 25 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I’m still experiencing a similar problem - starting the shell the first time is no problem, only when I manually source ~/.zshrc the formatting of suggestion is broken (the same as typed letters). The problem occurs only when using zsh-syntax-highlighting and zsh-autosuggestions together.

For any/all that continue to have problems with this. This is my work around. NOTE that I am using oh-my-zsh with repos loaded in .oh-my-zsh/custom/plugins

plugins=(all your normal plugins here)

if [ -z "$_zsh_custom_scripts_loaded" ]; then
  _zsh_custom_scripts_loaded=1
  plugins+=(zsh-autosuggestions zsh-syntax-highlighting)
fi

@ericfreese The following patch fixes the problem for me and keeps both z-asug and z-sy-h working. Why does z-asug reinstall itself at every precmd?

diff --git a/src/start.zsh b/src/start.zsh
index 54f5bb8..fc3a7cd 100644
--- a/src/start.zsh
+++ b/src/start.zsh
@@ -7,6 +7,7 @@
 _zsh_autosuggest_start() {
        _zsh_autosuggest_check_deprecated_config
        _zsh_autosuggest_bind_widgets
+       add-zsh-hook -d precmd _zsh_autosuggest_start
 }

 autoload -Uz add-zsh-hook

edit (to users who want to test this patch): Remember to run make after applying this patch!

This is only when sourcing the .zshrc for the second time correct?

I.e. You don’t get a segfault if you do this?

% zsh -f
% . ~/.zshrc

I’ve been experimenting a bit.

Some test cases:

A) Sourcing only this plugin multiple times (no segfault)

% zsh -f
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% # no segfaults here...

B) Sourcing only the zsh-syntax-highlighting plugin multiple times (no segfault)

% git -C ~/Code/zsh-syntax-highlighting rev-parse --short HEAD
7044c19
% zsh -f
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% # no segfaults here...

C) Sourcing zsh-syntax-highlighting multiple times, then this plugin multiple times (no segfault)

% zsh -f
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% # no segfaults here...

D) Sourcing this plugin (any number of times), then zsh-syntax-highlighting (segfault)

% zsh -f
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% zsh: segmentation fault  zsh -f

E) Sourcing both plugins at the same command prompt (see https://github.com/tarruda/zsh-autosuggestions/issues/107#issuecomment-183822932) (no segfault)

% zsh -f
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh; source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% # no segfaults here...

So, yes there is some sort of bug here. I’ll look into exactly what triggers these segfaults and see if there’s something we can do in this plugin to avoid them.

In the mean time, the obvious workaround is to not source these plugins at different prompts. Just put them in your .zshrc and only source them once. Start a new terminal session when making changes to your config instead of sourcing your .zshrc again.

Yeah! This works well:

zplug "zsh-users/zsh-autosuggestions", at:develop
zplug "zsh-users/zsh-syntax-highlighting", defer:3

When to expect this in master?

To everyone who says the workaround https://github.com/zsh-users/zsh-autosuggestions/issues/126#issuecomment-217041261 doesn’t work for them: note that you need to run make after applying that patch!

Is there any solution for this? The workaround doesn’t work for me