cea-hpc / modules

Environment Modules: provides dynamic modification of a user's environment
http://modules.sourceforge.net/
GNU General Public License v2.0
711 stars 109 forks source link

Implement a `command-not-found`-like feature #541

Open cmarqu opened 2 months ago

cmarqu commented 2 months ago

Is your feature request related to a problem? Please describe.

It is sometimes not at all easy to find out which module(s) would provide a certain executable. In Linux distributions, there are tools like command-not-found which suggest which package to install in such a case.

Describe the solution you'd like

It would be nice if I could ask modules which specific module I need to load to get an executable in PATH.

Describe alternatives you've considered

Additional context

A very simplistic implementation would be to loop over all (or latest) modules, load each of them in a subshell, check if the binary is available (using command -v, which), and print the module name if so.

Speeding things up with e.g. parallel processing and/or caching could come later.

xdelaruelle commented 2 months ago

Many thanks Colin for this suggestion. I have this use case in mind since a bit of time and it is good to see that someone else would like to see this use case covered in Modules.

The Mii tool (https://github.com/codeandkey/mii) implements such feature as an external tool using module command.

I think a find-and-exec sub-command may be added on Modules to cover this use case. It will parse the content of the directories added to PATH in all modulefiles. Cache will help to speed such lookup.

Then, autoinit sub-command may define command_not_found_handle bash/zsh shell function to call module find-and-exec to find executable and run it.