prefix-dev / pixi

Package management made easy
https://pixi.sh
BSD 3-Clause "New" or "Revised" License
3.22k stars 176 forks source link

Shell completions in pixi global & pixi envs #2366

Open wolfv opened 2 days ago

wolfv commented 2 days ago

This issue concerns pixi, but also the wider conda ecosystem. I would like to come up with a mechanism to support shell completion files easily.

Shell completions are usually initialized by sourcing a shell script that injects a number of completion functions into the context of the shell. Homebrew has a pretty solid mechanism to generate & source shell completions and I think we should follow that. Conda also has the "activation" script mechanism, but it is meant for a slightly different purpose and it's also beneficial to not execute shell completion hooks in a context where it's not needed (to keep activation scripts fast).

For these reasons I would like to introduce a new folder $PREFIX/share/<shell>/completions/. Of course, packages would have to adopt this folder (which is why we should also write a CEP about it).

For bash, zsh or fish, we should create snippets to load all the completions scripts from the folder. And pixi shell should automatically source this snippet.

For pixi global, we should source all relevant snippets (similar to the binary expose function) we should write the completions to be sourced to a file like ~/.pixi/completions/bash/completions.sh. This file would need be kept in sync with any changes.

wolfv commented 2 days ago

This is how homebrew does the generation:

https://github.com/Homebrew/homebrew-core/blob/9552bdb9a3af5028ba1248f8fe77a2877d99824c/Formula/r/rattler-build.rb#L37

Or like this:

https://github.com/Homebrew/homebrew-core/blob/9552bdb9a3af5028ba1248f8fe77a2877d99824c/Formula/s/sd.rb#L25-L27

pavelzw commented 2 days ago

for pixi global i feel it might be a bit more stable to write the completions to ~/.pixi/completions/bash/<env-name>.sh and just source all of them in ~/.pixi/completions/bash-completion.sh