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

In ZSH, use of compinit clobbers existing completions #1526

Closed
bherw opened this issue Dec 20, 2021 · 5 comments · Fixed by #1548
Closed

In ZSH, use of compinit clobbers existing completions #1526

bherw opened this issue Dec 20, 2021 · 5 comments · Fixed by #1548
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛
Milestone

Comments

@bherw
Copy link
Contributor

bherw commented Dec 20, 2021

I'm generating completions for a bunch of commands in a row and trying to load all their completions sequentially like so:

if [ -d "$SCRIPTDIR/../bash_completion.d" ]; then
	for bcp in "$SCRIPTDIR/../bash_completion.d"/*.sh; do
		source "$bcp"
	done
fi

This works great in bash, but unfortunately in zsh the "compinit" call at the top of each script resets all the rest of the completions, resulting in only the last command alphabetically in the directory getting any completions.

I've worked around this for now by adding an alias compinit= before the loop.

Based on https://zsh.sourceforge.io/Doc/Release/Completion-System.html, compinit defines compdef, so I think testing if it's already loaded as follows should be enough to avoid clobbering completions:

if ! type compdef > /dev/null; then
    compinit
fi
@remkop
Copy link
Owner

remkop commented Dec 20, 2021

Thank you for raising this!
Can you confirm that this works for both bash and zsh?

@remkop remkop added theme: auto-completion An issue or change related to auto-completion type: bug 🐛 labels Dec 20, 2021
@remkop remkop added this to the 4.6.3 milestone Dec 20, 2021
@bherw
Copy link
Contributor Author

bherw commented Dec 22, 2021

I haven't tried editing the autocomplete scripts directly yet, but bash seems fine with it if I put it in a if [ -n "$ZSH_VERSION" ] block. The issue only affects the use of ZSH's compinit in that block; bash worked fine already, so as long as it's not causing a syntax error it should be fine.

I'll see if I can find some time to make a PR; should be a quick change.

@remkop
Copy link
Owner

remkop commented Dec 22, 2021

I'll see if I can find some time to make a PR; should be a quick change.

That would be great, thank you! Most of my time is occupied with Log4j recently...

@remkop
Copy link
Owner

remkop commented Jan 17, 2022

@bherw Have you had a chance to look at this?

@bherw
Copy link
Contributor Author

bherw commented Jan 17, 2022

I have a patch that should work in theory but unfortunately I don't have access to the programs I was working on before at this point so I'll need to rebuild something similar to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants