Different approach to sourcing foreign environment files #13318
dilr
started this conversation in
Show and tell
Replies: 1 comment
-
|
Polyglot is very cunning, I like that! I'm the author of what was formerly the bash-env plugin for Nushell. It was rather a pain maintaining it as a plugin, so it got a lot simpler, and became simply a Nu module and accompanying Bash script. Good to see ongoing innovation here. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is half a show and tell, and half me asking if I can add a different approach to sourcing foreign environments to the nushell cookbook.
My approach is a template for a polyglot script (meaning it is both a valid bash script and a valid nushell script) which first runs as bash to interpret the ".env" file, and then re executes itself as nushell, which gives you access to the environment. There is also a guard such that if the user executes it as a nushell script, the script will re-execute itself as a bash script to set up the environment before executing as a nushell script again.
The advantages of this approach is that it doesn't require a plugin like "bash-env" does, so it doesn't need the user to install anything besides nushell and bash. Also, it does not require nushell to parse the environment like "capture-forign-env" does. Therefore it is not tripped up by environmental variables which have newlines and/or quotes in them. The disadvantage is that the environmental setup needs to happen at the beginning of the script. Also, most people aren't that familiar with polyglot scripts, so it might cause some headaches if someone wanted to modify the approach.
Here is the template, with comments explaining the inner workings:
I would appreciate feedback on if this approach is acceptable for the cookbook, and also feedback on if some part seems unnecessarily unclear.
EDIT: made polyglot switch significantly less clever and more robust.
Beta Was this translation helpful? Give feedback.
All reactions