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

Mamba completion should not call compinit #1910

Closed
AntoinePrv opened this issue Sep 9, 2022 · 1 comment · Fixed by #1911
Closed

Mamba completion should not call compinit #1910

AntoinePrv opened this issue Sep 9, 2022 · 1 comment · Fixed by #1911

Comments

@AntoinePrv
Copy link
Member

I spend a bit of time investigating why micromamba completion would not work with my ZSH config, or would work depending where micromamba shell hook was called.

ZSH completion system is quite complex, but I found a similar issue on nvm-sh/nvm#2489 as well as this SO question.

There it is argued that compinit should be called only once, and preferably by the user in their zshrc (to make sure it is only called once).
The later would change the behaviour of micromamba which does not assume that the user need to edit their zshrc files, and so similarily the nvm folks decided to only conditionally call compinit in nvm-sh/nvm#2490.

I tested locally that this works for micromamba and so I propose we adopt a similar approach, namely, replacing

autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit

with

if ! command -v compinit > /dev/null; then
  autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
    compinit -u
  else
    compinit
  fi
fi
autoload -U +X bashcompinit && bashcompinit
@AntoinePrv
Copy link
Member Author

For future reference, ZSH completion system is also richer than what we are doing (bashcompinit), it is for instance possible to add description for the keywords being completed.

I know of this executable that also need to call itself during completion to find dynamic info (e.g. the environment name in our case).
https://github.com/go-task/task/blob/master/completion/zsh/_task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant