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
remove let-env, focus on mutating $env #9574
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now it looks good to me 👌
of course this breaks integration with other tools 👍
@jntrnr, the failing test is here in |
Looks like starship and virtual already use |
atuin looks like it will break: https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not understand why we need to use load-env
in the last commit 😕
@amtoine because the path variable is coming from a variable. |
@jntrnr, i've added the integration scripts above to the body of the PR 👌 |
oooooh very good catch 😱 👏 👏 |
Zoxide looks like it will also break: https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt |
i propose to make this a draft to avoid merging the PR before we have fixed the integration scripts 😮 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe LetEnvDeprecated
should go inside crates/nu-command/src/deprecated/
as the other deprecated commands? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks about right to me... LET'S BREAK IT 💪 😤
related to nushell/nushell#9574 Commands used ```nushell sd --string-mode "let-env " '$env.' **/* git rst before_v0.60/ ```
related to nushell/nushell#9574 Commands used ```nushell sd --string-mode "let-env " '$env.' **/* git rst before_v0.60/ ```
This is a great change, thank you! I was getting quite confused, but this also breaks quite some scripts. Since the fix is mechanical, would it be meaningful to produce |
a few commands i know that should do this migration 😋
i did not try them but i think they should do it 😋 |
I had an alias I can probably work around this by defining $ # create alias then test
$ # ---------------------
$ alias set-py = $env.PY = (which python)
$ alias set-py = ($env.PY = (which python))
$ alias set-py = {$env.PY = (which python)}
$ # all of the above are invalid syntax
$
$ alias set-py = do {$env.PY = (which python)}
$ set-py # should create $env.PY
$ $env.PY # no errors but also does not work since closures don't mutate
$
$ # the one below works as a workaround, though maybe a bit ugly
$ alias set-py = load-env {XY: (which python)}
$ set-py # no error here
$ $env.XY # works! |
@hyiltiz
|
Is there a benefit for defining it as a command vs. alias, except the fact that in a command there is much larger flexibility to do arbitrarily complex things (may not be desirable since by alias I meant to show the shallowness of implementation). I'll just use |
maybe @kubouch might have more information about the aliases as he rewrote them completely not so long ago, but i'd say that by design aliases do alias to commands, not language constructs.
yeah, as |
This did break compatibility with some other tools (I experience it with Starship) because the updated scripts have not been included into a release yet (not to mention it required hand-fixing the env and config files). I guess it's too late now, but instead of turning the old sytnax into a hard error it would have been better to deprecate it (as in, just rise a warning) for some time. Hopefully this will fix itself as the new scripts are released. Overall, not a great user experience. |
yeah, the fix i wrote on the Starship side is ahead the latest release by 7 commits 😭
the deprecation system definitely needs love 😌
i can confirm you it will 👌
again, sorry for the inconvenience... |
Description
For years, Nushell has used
let-env
to set a single environment variable. As our work on scoping continued, we refined what it meant for a variable to be in scope usinglet
but never updated howlet-env
would work. Instead,let-env
confusingly created mutations to the command's copy of$env
.So, to help fix the mental model and point people to the right way of thinking about what changing the environment means, this PR removes
let-env
to encourage people to think of it as updating the command's environment variable via mutation.Before:
Now:
It's also a good reminder that the environment owned by the command is in the
$env
variable rather than global like it is in other shells.User-Facing Changes
BREAKING CHANGE BREAKING CHANGE
This completely removes
let-env FOO = "BAR"
so that we can focus on$env.FOO = "BAR"
.Tests + Formatting
After / Before Submitting
integration scripts to update: