opam icon indicating copy to clipboard operation
opam copied to clipboard

Should $(opam env) or .opam/opam-init/* setup paths for shell completion scripts ?

Open dbuenzli opened this issue 11 months ago • 4 comments

I'm not sure whether this belongs to the opam-repository or here but since this could interact with what opam does for shell detection I'm doing it here.

opam extends quite a few configuration paths so that stuffs gets looked up in the opam prefix (e.g. PATH, MANPATH[^1]). I was wondering if perhaps opam could do the same for shell completion scripts according to the current shell. That way packages can simply install completion scripts in the prefix where the various shell expect them and they get automatically picked up by the user shell as packages come and go.

It seems at least me an another person are interested :-)

What do you think ?

[^1]: On macos I don't know how, but invoking manpath has it.

dbuenzli avatar Mar 20 '25 22:03 dbuenzli

From what I have understood so far.

This would entail:

  • For zsh, extending FPATH:
    FPATH="$(opam var share)/zsh/site-functions:${FPATH}"
    
  • For bash, (assuming bash-completion) extending XDG_DATA_DIRS:
    XDG_DATA_DIRS="$(opam var share):${XDG_DATA_DIRS}"
    
    (this makes bash look into $(opam var share)/bash-completion/completions).

dbuenzli avatar Mar 22 '25 01:03 dbuenzli

In fact I really think it should because otherwise, if the users do that themselves as suggested here, they get all sorts of confusing behaviours as they opam switch.

dbuenzli avatar Jul 20 '25 07:07 dbuenzli

I have some spare cycles to implement this if it's desirable to the opam maintainers

It seems to me like opam env is the natural place, given that it currently handles MANPATH?

WardBrian avatar Nov 17 '25 15:11 WardBrian

@WardBrian we haven't thought about it much so far (there may be security concerns, idk), but a PR is always appreciated. opam env is probably the place yes

kit-ty-kate avatar Nov 17 '25 16:11 kit-ty-kate