elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.62k stars 300 forks source link

[FR] Completions directory on Linux #1564

Open ajeetdsouza opened 2 years ago

ajeetdsouza commented 2 years ago

Bash, fish, and zsh all have a completions directory on Linux, where applications can add their completion files. Does Elvish have anything similar? If not, consider this a feature request.

xiaq commented 2 years ago

Completion files can be installed like other modules into a global module search directory (https://elv.sh/ref/command.html#module-search-directories).

There is no automatic discovery of completion files though; the user would have to import them manually with use.

ajeetdsouza commented 2 years ago

Would it be feasible to implement automatic discovery of completion files?

krader1961 commented 2 years ago

Would it be feasible to implement automatic discovery of completion files?

Yes, but it probably requires some discussion over a period of several months to determine if the pro's outweigh the con's. At this time Elvish does not automatically import any module other than builtin. So one con is that automatically importing completion modules is behavior different than for non-completion modules. On the other hand, interactive command completion modules are fundamentally different from non-completion modules and it might be friendlier to automatically import them. On the other hand, a completion module can contain arbitrary Elvish code -- not just command completion code. And thus auto-importing completion modules could be abused to bypass the usual requirement to use a module. That could, perhaps, be mitigated by putting completion modules in a special namespace that isn't searched when resolving an interactive command.

xiaq commented 1 month ago

Revisiting this, it would make sense for the default fallback completer to autoload completion modules. So something like this could work:

This autoloader can already be implemented in Elvish code today. However, I am a bit hesitant to commit to this scheme because I'm going to revisit the module system in the near future, and that might mean a slightly different scheme for installing completion scripts. Having two different ways of packaging completion modules can be quite confusing for distributions.

So I'll keep this on hold for now until I have revisited the module system.