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

Nushell support in shellenv command #19345

Closed
1 task done
paaloeye opened this issue Feb 21, 2025 · 3 comments
Closed
1 task done

Nushell support in shellenv command #19345

paaloeye opened this issue Feb 21, 2025 · 3 comments
Labels
features New features

Comments

@paaloeye
Copy link

paaloeye commented Feb 21, 2025

Verification

Provide a detailed description of the proposed feature

Essentially, what I'd like to achieve is brew shellenv supporting Nushell.

Proposed user interface:

^/opt/homebrew/bin/brew shellenv nushell
    | from <format>
    | into record
    | load-env

Nushell supports loads of formats, and I'm happy to discuss which one suits the best. csv is probably the easiest:

^/opt/homebrew/bin/brew shellenv nushell
    | from csv
    | into record
    | load-env

It would be too too much to ask to provide support for Nushell from Homebrew alone, so we'll provide the PR if the proposed UX is agreed upon

References

What is the motivation for the feature?

Currently, it isn't easy to convert your zsh or/and bash rc files containing brew installation to Nushell.
That is mostly due to Nushell not supporting eval, and that is not going to change anytime soon.

FYI: A similar question has been asked before albeit with broader scope: #17221

How will the feature be relevant to at least 90% of Homebrew users?

Purely based on the number of stars on Github, one can assume that both audiences are of similar sizes. Technology-wise, there is a great level of intersection between the audiences too. I can personally vouch for that.

What alternatives to the feature have been considered?

^/opt/homebrew/bin/brew shellenv | lines | parse 'export {name}="{value}";' | transpose -r | into record | load-env

That doesn't update $env.PATH, so you have to update it in your config.nu.

References:

@paaloeye paaloeye added the features New features label Feb 21, 2025
@MikeMcQuaid
Copy link
Member

@paaloeye Assuming the desired output is achieved: what would the Nushell equivalent of eval $(brew shellenv) be?

Heads up that this is probably the type of thing that it will depend on how complex the PR ends up being (i.e. lines of code) as to whether we accept it or not.

@paaloeye
Copy link
Author

brew shellenv nushell | from csv | into record | load-env

Here is what I ended up with in env.nu when I installed brew.

/opt/homebrew/bin/brew shellenv csh 
      | lines 
      | parse --regex 'setenv (\w+) "?(.+)"?;' 
      | transpose -r 
      | into record 
      | load-env

That produces roughly the following environment variables:

capture0 capture1
HOMEBREW_PREFIX /opt/homebrew
HOMEBREW_CELLAR /opt/homebrew/Cellar
HOMEBREW_REPOSITORY /opt/homebrew
PATH /opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/Cellar/zigup/2025.01.02/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Ghostty.app/Contents/MacOS""
MANPATH :${MANPATH}
INFOPATH /opt/homebrew/share/infotest ${?INFOPATH} -eq 1 && echo :${INFOPATH}

An attentive reader can see, that MANPAGE and INFOPATH might cause some issues down the line.

Desired output of brew shellenv nushell:

HOMEBREW_PREFIX,HOMEBREW_CELLAR,HOMEBREW_REPOSITORY,PATH,MANPATH,INFOPATH
/opt/homebrew,/opt/homebrew/Cellar,/opt/homebrew,/opt/homebrew/bin:/opt/...,,/opt/homebrew/share/info

Does it answer your question @MikeMcQuaid ?

@MikeMcQuaid
Copy link
Member

@paaloeye It does, thanks! We'll review a PR for this. Assuming you'll be the one creating the PR so closing with that in mind for now. Happy to continue discussion here and/or in the PR. Shout if you need help.

@MikeMcQuaid MikeMcQuaid closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
features New features
Projects
None yet
Development

No branches or pull requests

2 participants