Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad pattern: funcs=(\n ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n ) #335

Closed
muuvmuuv opened this issue Sep 8, 2021 · 36 comments
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@muuvmuuv
Copy link

muuvmuuv commented Sep 8, 2021

  • zsh-autocomplete version: latest I assume
  • Zsh version: zsh 5.8 (x86_64-apple-darwin20.0)
  • Framework: Starship
  • Plugin manager: zinit
  • Operating system: macOS ARM latest release

I was not able to reproduce it with the template you provided because I only get this error on loading the shell:

~/Development
;
(anon):22: bad pattern: funcs=(\n      ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n  )

My zshrc:

eval "$(starship init zsh)"

export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"

alias vim="nvim"
alias dir="ls -lah"
alias zshrc="code ~/.zshrc"

# Globbing

setopt NO_CASE_GLOB
setopt EXTENDED_GLOB

# History

HISTORY_IGNORE="(ls|dir|cd|pwd|exit|cd ..|..|*venv*)"

setopt EXTENDED_HISTORY
setopt INC_APPEND_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_REDUCE_BLANKS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_IGNORE_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_SAVE_NO_DUPS

# Misc

setopt AUTO_CD
setopt MENU_COMPLETE
setopt NO_LIST_AMBIGUOUS

# Settings

zstyle ':autocomplete:*' min-input 2
zstyle ':autocomplete:tab:*' fzf-completion yes

# Plugins

source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

zinit wait lucid light-mode for \
  marlonrichert/zsh-autocomplete \
  atinit"zicompinit; zicdreplay" \
      zdharma/fast-syntax-highlighting \
  blockf atpull'zinit creinstall -q .' \
      zsh-users/zsh-completions

zinit ice from"gh-r" as"program" bpick"*arm*"
zinit light junegunn/fzf

My zsh_history looks like this:

: 1631085612:0;cd app
@muuvmuuv muuvmuuv added the bug Something isn't working label Sep 8, 2021
@muuvmuuv
Copy link
Author

muuvmuuv commented Sep 8, 2021

Just tried with the Homebrew zsh Version "zsh 5.8 (arm-apple-darwin20.2.0)" same error.

@marlonrichert
Copy link
Owner

marlonrichert commented Sep 8, 2021

It's actually a bug in Zinit: https://github.com/zdharma/zinit/issues/366

I had a workaround for it, but it looks like it doesn't work anymore. I will add a new workaround.

However, I do strongly recommend you switch to a plugin manager that doesn't do as much nonsense.

@marlonrichert marlonrichert added help wanted Extra attention is needed and removed bug Something isn't working labels Sep 8, 2021
@marlonrichert marlonrichert self-assigned this Sep 8, 2021
@muuvmuuv
Copy link
Author

muuvmuuv commented Sep 8, 2021

I am open for suggestions. I only have fzf and two other zsh plugins I need. I would even add them in a fast way natively without a pm but I have no clue how to do that. I will take a closer look at that the next days, maybe I really dont need any.

@marlonrichert
Copy link
Owner

If you do want to use a plugin manager, I would naturally recommend Znap. 🙂

@muuvmuuv
Copy link
Author

muuvmuuv commented Sep 8, 2021

Okay wow you are amazing. Now I don't even see any blink or delay its just up in 0.1ms xD Combined it with Starship.rs and it's just the perfect fit for it.

@marlonrichert
Copy link
Owner

Great to hear! 😃


PS: If you enjoy using my software, please consider sponsoring me.

@weilbith
Copy link

This issue is still there, right?

@muuvmuuv
Copy link
Author

No, gone after updating, at least on my end.

@marlonrichert
Copy link
Owner

@weilbith Can you give me a reproducible test case?

@weilbith
Copy link

weilbith commented Oct 1, 2021

Hmm. I just created a new user. And then I do:

$ zsh
% source /usr/share/zinit/zinit.zsh
% zinit lucid light-mode for marlonrichert/zsh-autocomplete
# installation output...
(anon):22: bad pattern: funcs=(\n     ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n  )
%

That appears on each new shell I open. Autocomplete doesn't work at all (god damn I love your plugin so much it is a nightmare without). And it is a little worse because Powerlevel10k instant prompt reports tons of output because something is logging before the first prompt. Very annoying atm.

@marlonrichert marlonrichert added the bug Something isn't working label Oct 3, 2021
@Jackenmen
Copy link

I'm seeing the same issue with zcomet:

(anon):22: bad pattern: funcs=(\n      ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n  )
Cannot source /home/ubuntu/.zcomet/repos/marlonrichert/zsh-autocomplete/zsh-autocomplete.plugin.zsh.
ubuntu-virtual-machine% 

Contents of .zshrc:

# Clone zcomet if necessary
if [[ ! -f ${ZDOTDIR:-${HOME}}/.zcomet/bin/zcomet.zsh ]]; then
  command git clone https://github.com/agkozak/zcomet.git ${ZDOTDIR:-${HOME}}/.zcomet/bin
fi

source ${ZDOTDIR:-${HOME}}/.zcomet/bin/zcomet.zsh

zcomet load marlonrichert/zsh-autocomplete

@marlonrichert marlonrichert added duplicate This issue or pull request already exists and removed bug Something isn't working help wanted Extra attention is needed labels Oct 5, 2021
@marlonrichert
Copy link
Owner

marlonrichert commented Oct 5, 2021

I didn’t realize it before, but this issue is a duplicate of #339.

Also, 96fec14 doesn’t fix the problem you have; it’s a workaround for another Z Init problem. Apologies for the confusion.

@weilbith It’s caused by a bug in Z Init: https://github.com/zdharma/zinit/issues/543. It’s not that hard to fix, though. See my comment there for an explanation.

@jack1142 Looks like Z Comet has the same bug as Z Init. Again, see my comment on the Z Init issue for an explanation. When you open an issue on Z Comet’s repo, make sure you include a link to my comment.

And in case you didn’t know it: I maintain a fast, lightweight & simple plugin manager called Znap, which naturally doesn’t suffer from the same problem. 😉

@marlonrichert
Copy link
Owner

No, gone after updating, at least on my end.

@muuvmuuv Because you are using Znap now, right? Because the problem still hasn’t been fixed in Z Init. 🙂

@marlonrichert marlonrichert changed the title Bad pattern .autocomplete.*~*.zwc(N-.:a) bad pattern: funcs=(\n ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n ) Oct 5, 2021
@weilbith
Copy link

weilbith commented Oct 5, 2021

And in case you didn’t know it: I maintain a fast, lightweight & simple plugin manager called Znap, which naturally doesn’t suffer from the same problem. wink

I know. I'm thinking about alternatives. But Znap still has no lazy loading, correct? It also just costs time to switch. Atm a good question what would take more time. 😑

@weilbith It’s caused by a bug in Z Init: zdharma/zinit#543. It’s not that hard to fix, though. See my comment there for an explanation.

So I wen to $XDG_CACHE_HOME/zinit/plugins/marlonrichert---zsh_autocomplete and run zcompile -R zsh-autocomplete.plugin..zsh there. No autocompletion works but I get tons of errors on a new shell which looks like that:

compinit:503: no such file or directory: /home/thore/.cache/zinit/completions/_yaourt
compinit:shift:505: shift count must be <= $#
compinit:503: no such file or directory: /home/thore/.cache/zinit/completions/_yarn
compinit:shift:505: shift count must be <= $#
compinit:503: no such file or directory: /home/thore/.cache/zinit/completions/_zcash-cli
compinit:shift:505: shift count must be <= $#

@marlonrichert
Copy link
Owner

marlonrichert commented Oct 5, 2021

But Znap still has no lazy loading, correct?

No, not correct. 🙂 Znap does have lazy loading:

% znap help function
Usage: znap function <func name> ... <init code>
Create a set of lazy-loading functions.

For example, here's how to set up lazy loading for pyenv, pip, pipx and pipenv and their respective completion functions:

znap function _pyenv pyenv 'eval "$( pyenv init - --no-rehash )"'
compctl -K    _pyenv pyenv

znap function _pip_completion pip 'eval "$( pip completion --zsh )"'
compctl -K    _pip_completion pip

znap function _python_argcomplete pipx 'eval "$( register-python-argcomplete pipx  )"'
complete -o nospace -o default -o bashdefault \
           -F _python_argcomplete pipx

znap function _pipenv pipenv 'eval "$( pipenv --completion )"'
compdef       _pipenv pipenv

This way, initialization code for these commands won't run until you actually try to execute the command or try to invoke completion on it. 🙂

If you really want to go wild, you could even replace the eval "$( <command> )" statements in there with znap eval "<command>", but in my experience, that's not really necessary.

@marlonrichert
Copy link
Owner

marlonrichert commented Oct 5, 2021

So I wen to $XDG_CACHE_HOME/zinit/plugins/marlonrichert---zsh_autocomplete and run zcompile -R zsh-autocomplete.plugin..zsh there. No autocompletion works but I get tons of errors on a new shell which looks like that:

compinit:503: no such file or directory: /home/thore/.cache/zinit/completions/_yaourt
compinit:shift:505: shift count must be <= $#
compinit:503: no such file or directory: /home/thore/.cache/zinit/completions/_yarn
compinit:shift:505: shift count must be <= $#
compinit:503: no such file or directory: /home/thore/.cache/zinit/completions/_zcash-cli
compinit:shift:505: shift count must be <= $#

I cannot reproduce that. Here's what I did:

% cd $(mktemp -d)
git clone --depth 1 -- https://github.com/zdharma/zinit.git $PWD/.zinit/bin
> .zshrc <<EOF
PS1="%# " PS2="  " RPS2="< %^"; setopt transientrprompt
source $PWD/.zinit/bin/zinit.zsh
zinit load marlonrichert/zsh-autocomplete
EOF
env -i HOME=$PWD ZDOTDIR=$PWD FPATH=$FPATH TERM=$TERM zsh -d

/tmp/tmp.5y9lh2d3MO/
Cloning into '/tmp/tmp.5y9lh2d3MO/.zinit/bin'...
remote: Enumerating objects: 180, done.
remote: Counting objects: 100% (180/180), done.
remote: Compressing objects: 100% (163/163), done.
remote: Total 180 (delta 10), reused 120 (delta 8), pack-reused 0
Receiving objects: 100% (180/180), 1.04 MiB | 1.34 MiB/s, done.
Resolving deltas: 100% (10/10), done.

Downloading marlonrichert/zsh-autocomplete...

Cloning into '/tmp/tmp.5y9lh2d3MO/.zinit/plugins/marlonrichert---zsh-autocomplete'...
▗ █████████████████████████ OBJ: 100, PACK: 3247/3247, COMPR: 100%, REC: 100%, RES: 100%          
Note: Compiling: zsh-autocomplete.plugin.zsh... OK.
Installed 10 completions. They are stored in $INSTALLED_COMPS array.
(anon):22: bad pattern: funcs=(\n      ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n  )
% zcompile -R .zinit/plugins/marlonrichert---zsh-autocomplete/zsh-autocomplete.plugin.zsh
% exec zsh -d
%

And now autocompletion works just fine.

You have probably have some config that changes the way zcompile parses the code. Try this instead:

% emulate zsh -c 'zcompile -UzR .zinit/plugins/marlonrichert---zsh-autocomplete/zsh-autocomplete.plugin.zsh'

This will invoke zcompile with default shell options and alias expansion disabled, which is what Z Init and Z Comet should be doing, too.

@muuvmuuv
Copy link
Author

muuvmuuv commented Oct 5, 2021

@marlonrichert Oh, I think you are right ^^ Did not think about that to be an issue with the pm rather than the plugin itself.

@marlonrichert
Copy link
Owner

Please disregard my comments so far as to what is the cause of the problem: On further investigation, it turns out that, actually, the only thing that fixes the problem, for both Z Init and Z Comet, is to zcompile from the command line. Changing the zcompile statement inside the code does nothing to solve it. There must be something that both of them change about the compilation progress, but I don't know what it is. 😕

@muuvmuuv
Copy link
Author

muuvmuuv commented Oct 5, 2021

At all here… Just use znap xD I really have less problems with it (thanks @marlonrichert). Can strongly recommend it!

@agkozak
Copy link

agkozak commented Oct 5, 2021

I see the same problem happening in Zim, which also automatically compiles such scripts.

@agkozak
Copy link

agkozak commented Oct 6, 2021

I can run this at the command line:

zsh -f
() { zcompile -R zsh-autocomplete.plugin.zsh; }
source zsh-autocomplete.plugin.zsh

with the same results:

(anon):22: bad pattern: funcs=(\n      ~zsh-autocomplete/functions/.autocomplete.*~*.zwc(N-.:a)\n  )

@marlonrichert
Copy link
Owner

@agkozak Huh, indeed. I wonder why it's not a problem when Znap compiles things?

@marlonrichert marlonrichert reopened this Oct 6, 2021
@marlonrichert
Copy link
Owner

I finally managed to figure it out: It's an unfortunate way in which compiled or autoloaded code in Zsh is not 100% equivalent to the original source code. But now that I now what causes it, I also know how to work around it.

@agkozak Thanks for your help in tracking down the root cause of the problem!

@agkozak
Copy link

agkozak commented Oct 6, 2021

You're very welcome. I was just working on a similar patch, but I was not sure how many instances of private needed to be changed. It looks as if you've done a very thorough job.

@agkozak
Copy link

agkozak commented Oct 6, 2021

I suspect the reason Znap didn't have a problem was because it already has zsh/param/private loaded when zcompile is run. I tested that out of the command line.

@marlonrichert
Copy link
Owner

Yes, that's exactly the reason I figured out, too.

@weilbith
Copy link

weilbith commented Oct 7, 2021

Thank you so much!! 🙏🏾
So nice to have my old full functional shell back. 😆

@weilbith
Copy link

weilbith commented Oct 7, 2021

Not sure if that is related, but since the update I get very often these messages while completing (hitting Tab on a path). It then always opens a new prompt with the same command I'm typing:

.autocomplete.complete-word.post:12: array parameter mbegin set in enclosing scope in function .autocomplete.complete-word.post
.autocomplete.complete-word.post:12: array parameter mend set in enclosing scope in function .autocomplete.complete-word.post

@marlonrichert
Copy link
Owner

I already fixed that in 8877a3b.

@weilbith
Copy link

weilbith commented Oct 7, 2021

I can confirm that my HEAD is 8877a3b but I still have this issue. 🤷🏾

@marlonrichert
Copy link
Owner

Do git pull again. It should be fixed now.

@weilbith
Copy link

weilbith commented Oct 7, 2021

Okay yes. But I first had to delete it. Dunno why. 🤷🏾
Thank you!

@marlonrichert
Copy link
Owner

Delete what?

@weilbith
Copy link

weilbith commented Oct 8, 2021

Delete what?

For some reason I had to delete the local clone of the plugin my plugin manager did. In this exact example for my I had to delete $XDG_CACHE_HOME/zinit/plugins/marlonrichert---zsh-autocomplete. It then reinstalled it and then it was fine. The HEAD of the commit before I deleted the directory and afterwards was the same. Dunno what was the difference here. Maybe some "compile" hook or so? 🤷🏾

@marlonrichert
Copy link
Owner

@agkozak I noticed that Z Comet is actually not that different in syntax from Znap and that you even copied some features from me. Rather than compete with each other, would you be interested in joining forces and merge our plugin managers into one?

@agkozak
Copy link

agkozak commented Oct 12, 2021

I'm deeply honored that you'd ask, @marlonrichert! But I see us as doing two rather different things. I support Zsh as far back as 4.3.11, whereas you take advantage of the most cutting-edge features of the latest versions of the shell. It seems that we have different aims.

I originally used a subset of Zinit's syntax, believe it or not! The whole point was to make my Zinit-based .zshrc work when I was using Zsh < 5.0.8. But when I decided to stop using Zinit and do my own thing, it seemed preferable to opt for a simpler, more Antigen-like syntax.

I do admire your project very much. I think the one element that I very consciously copied (as acknowledged in the code and the documentation) was your idea of using dynamic named directories for the Git repos. It is a very elegant feature.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants