Adding bash completion for a package

Hello, I was able to add the micronaut cli to https://github.com/moaxcp/nur. I would like to add the bash completion. Are there any easy examples of how to do this? Once this is done and working I plan on adding it to nixpkgs.

If I am not mistaken, the project already has bash completions here.

There is a comment in the top of that file that basically says that you should copy this to $out/etc/bash-completion.d (in your installPhase).

This does require that something sources the file from that location (during shell initialization).

The better approach might be to copy the completion file to $out/share/bash-completion/completions under the name of the command for which it provides completion (mn?) and then rely on the user having installed bash-completion which dynamically loads completions from that folder.

You can use the installShellFiles setup hook that’s available in Nixpkgs master. Search for installShellFiles in the manual.

2 Likes

It does have completion but I want to install it when a user adds the package to their system.

Thanks! I will try this when I get the chance.

I was able to fix this using installShellFiles. Thanks for the help!