Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookbook chapter on how to read env vars from foreign shell scripts #1292

Merged
merged 2 commits into from
Mar 10, 2024

Conversation

remmycat
Copy link
Contributor

@remmycat remmycat commented Mar 9, 2024

This originated from a conversation in the Nushell Discord, where I showed a less sophisticated version of this script in the #cool-scripts channel, and was asked to contribute it to the Cookbook.

Next to reviewing the code, please give your honest opinions on the text, and if you want me to change anything, I appreciate the feedback 🙂

You may of course also just edit anything yourself if that is preferred.

I hope this is helpful to people!

@@ -137,6 +137,7 @@ export const sidebarEn: SidebarConfig = {
'help',
'system',
'parsing',
'foreign_shell_scripts',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I placed this here because it seemed like a good follower to the system and parsing documents, but I'm totally fine with it being moved to the bottom or somewhere else.

that the path to the `brew` binary depends on the OS and installation.

```
load-env (^/opt/homebrew/bin/brew shellenv | capture-foreign-env)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perhaps the most important part of the page: A quick example of how to use the capture command. Ideally, it should be something more widely understandable. People not using Homebrew don't know what brew shellenv is. I think even load-env ('script.sh' | capture-foreign-env) would do. It is not immediately clear the $in should be a script filename, some people might try to do open script.sh | capture-foreign-env or similar to pipe in the script contents.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(By "people" I mean "me" as these things came to mind when reading it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes a lot of sense! I'll create a simpler, highlighted example tomorrow and fix a few leftover typos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kubouch Actually, after rereading your comment: I didn't plan for you to be able to specify a script name, and I don't think it works, unless I missed something about eval.

So, open or open --raw would be the way to go, when having an existing script file. I liked having only one input method and thought it's important to allow the piping-in of the contents because tools generating env-var-scripts often pipe the script to stdout. Like brew in this case.

But I'm up for suggestions!
For now I'd add the example with open

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then I misunderstood. It's not clear whether $in should be a script name or a source string, I didn't read the script source that thoroughly. Then the example could be load-env (open script.nu | capture foreign-env) or similar.

Side note: You can check bass if you didn't know it. A similar idea but for running bash scripts in fish, written in Python.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, no worries!
I updated the PR and tried to be a little more clear about this.

@fdncred
Copy link
Collaborator

fdncred commented Mar 9, 2024

oooh, nice work!

@kubouch
Copy link
Contributor

kubouch commented Mar 10, 2024

Perfect, thanks!

@kubouch kubouch merged commit 7dd4606 into nushell:main Mar 10, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants