Zsh-autosuggestions: Parse error since last update

Created on 17 Jun 2019  路  12Comments  路  Source: zsh-users/zsh-autosuggestions

Hi,

I just updated zsh-autosuggestions via pacman and since then I have a parse error:

/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh:9: defining function based on alias `_complete'
/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh:571: parse error near `()'

update log from pacman:

[2019-06-17 03:17] [ALPM] upgraded zsh-autosuggestions (0.5.2-1 -> 0.6.0-1)
bug reproduced

Most helpful comment

I got the same error message today after updating. Did some searching and found robbyrussell/oh-my-zsh#6723 that described a similar error message.

I tried the same change as the author of that issue did, adding the function keyword before the function, and it solved the problem.
https://github.com/zsh-users/zsh-autosuggestions/blob/b3b34eab49b8e44f2df93d746640329a45722c0b/zsh-autosuggestions.zsh#L571-L574

    function _complete() {
        unset 'compstate[vared]'
        _original_complete "$@"
    }


https://github.com/robbyrussell/oh-my-zsh/issues/6723#issuecomment-381220834

That said, the syntax func() { is valid zsh, so based on your error message you're probably sourcing .zsh_functions with another shell that doesn't support that.

The last comment in the thread gives some insight into what the source of this error may be. I will keep looking to see if I can find a better fix to this problem.

All 12 comments

I have the same issue

Me too

Hi, thanks for reporting. I'm not immediately able to reproduce, so I'll need some more info from either of you.

  1. Can you reproduce this without running other commands in your zshrc?
% zsh -df
% source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh # or whatever the path is

If not, can you please comment out sections of your init files (.zshrc, etc.) until we narrow down the root cause of the issue?

  1. What version of zsh are you running?
% echo $ZSH_VERSION
  1. What zsh options do you have enabled?
% setopt
  1. When running
% zsh -df
% source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

I have no error message

  1. zsh 5.7.1 (x86_64-pc-linux-gnu)

3.

% setopt
alwaystoend
autocd
autopushd
nobeep
completeinword
correctall
extendedglob
extendedhistory
noflowcontrol
histexpiredupsfirst
histignoredups
histignorespace
histverify
incappendhistory
interactive
interactivecomments
longlistjobs
monitor
promptsubst
pushdignoredups
pushdminus
sharehistory
shinstdin
zle

After commenting/de-commenting it would seems that the issue come from this part (especially the call to bash_source):

__completion_loader() {
    compdef "$2=$1"
}
bash_source() {
  alias shopt=':'
  alias _expand=_bash_expand
  alias _complete=_bash_comp
  emulate -L sh
  setopt kshglob noshglob braceexpand
  local name=$(basename $1)
  alias _completion_loader=__completion_loader $name

  source "$@"
}
have() {
  unset have
  (( ${+commands[$1]} )) && have=yes
}
bash_source /usr/share/bash-completion/completions/aurman

IIRC, this code was to get autocompletion for aurman from bash completion scripts but it's been a long time since I've touch zsh's configuration file so I'm not completely sure what it does.

I got the same error message today after updating. Did some searching and found robbyrussell/oh-my-zsh#6723 that described a similar error message.

I tried the same change as the author of that issue did, adding the function keyword before the function, and it solved the problem.
https://github.com/zsh-users/zsh-autosuggestions/blob/b3b34eab49b8e44f2df93d746640329a45722c0b/zsh-autosuggestions.zsh#L571-L574

    function _complete() {
        unset 'compstate[vared]'
        _original_complete "$@"
    }


https://github.com/robbyrussell/oh-my-zsh/issues/6723#issuecomment-381220834

That said, the syntax func() { is valid zsh, so based on your error message you're probably sourcing .zsh_functions with another shell that doesn't support that.

The last comment in the thread gives some insight into what the source of this error may be. I will keep looking to see if I can find a better fix to this problem.

Thanks @n3f4s and @phillebaba. It looks like adding the "function" keyword fixes the issue.

Please try out fixes/alias-parse-error branch (PR #443) and let me know if it solves the issue for you.

It fixes the error for me.

For me too

Ok merged. Will go out with the next release. Thanks all

v0.6.1 released for this.

Thank you for the quick bug fix! I also verified that the fix works.

I flagged the arch package so that hopefully it gets updated as soon as possible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clay-f picture clay-f  路  7Comments

daniele-orlando picture daniele-orlando  路  6Comments

NikKovIos picture NikKovIos  路  4Comments

mindyourlifeguide picture mindyourlifeguide  路  6Comments

srajasimman picture srajasimman  路  5Comments