TACC / Lmod

Lmod: An Environment Module System based on Lua, Reads TCL Modules, Supports a Software Hierarchy
http://lmod.readthedocs.org
Other
468 stars 122 forks source link

Feature request: nushell #704

Open MilesCranmer opened 1 month ago

MilesCranmer commented 1 month ago

Just wondering if anybody has started a nushell integration for Lmod?

See https://github.com/nushell/nushell and https://www.nushell.sh/ for info.

Perhaps one way to do it is through the overlay system: https://www.nushell.sh/book/overlays.html. But maybe it is enough to just write some aliases so nushell is interfaced as if it were bash.

rtmclay commented 1 month ago

You are the first person to mention nushell. If you are interested in having Lmod be supported by nushell, please submit a pull request to support this shell.

MilesCranmer commented 1 month ago

Sure, how should I get started?

rtmclay commented 1 month ago

Here are my suggestions:

  1. Study the init/sh.in file in the source and see how that works. It will work with bash
  2. See if you can define a shell function that works in nushell in your personal account for the "module" command
  3. Do the same for "ml" and "clearMT"
  4. If nushell supports system startup files like /etc/profile does for bash then figure how that works for nushell
  5. Now extend the your nushell startup files to do all the things that init/bash.in does
  6. Add your startup file for nushell to Lmod in the init directory and update the docs in docs/source/030_installing.rst on how your startup files work.
  7. Create a pull request
rtmclay commented 3 weeks ago

I'm closing this issue. If you get a chance to work on this, you can re-open this issue.

MilesCranmer commented 3 weeks ago

I'm still interested; please re-open. Just haven't had a chance to work much on this yet.

MilesCranmer commented 3 weeks ago

I don't think it will be that difficult. Basically whenever bash has

export CMD="..."

the nushell version would be

$env.CMD = "..."

The tricky part would be things like PATH as nushell treats that as an array rather than a :-separated string. For that one would do

std path add "/path/to/bin"

And string interpolation for e.g., "${MY_DIR}/path" would be

$"($env.MY_DIR)/path"
rtmclay commented 3 weeks ago

Lmod does not add to path and path-like variables. Instead it sets the variable to all values. I did not think about nushell would have a different syntax from Bash. You will have to create a lua file called nushell.lua which works like Bash.lua or Rc.lua. You will have to modify BaseShell.lua. All of these files are in the shells directory.

The way that Lmod works is that it generates text which is then evaluated by the shell. You should write a text file that contains some nushell commands and make sure that you can evaluate commands. In Bash/Zsh this looks like

     eval "$(...)"

where the ... is some like cat nushell.txt