-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Change environment variables to be case-preserving #12701
Conversation
Hopefully this will close this issue once and for all. My only question is whether all supported operating systems should be allowed case-insensitive access to env vars? |
I'll mention this PR here since it implemented the same thing but hasn't been finished: #11432 |
We already have
I was aware of that. The author of that PR has abandoned it for quite a while now. |
I just noticed that |
I think the challenging behaviour here is that we usually try to make sure that the same Nushell scripts can run on all operating systems, as long as they're not written in a very OS-specific way. So having this just be the case for Windows would make it possible for a Windows-based developer to write a script that won't work on other OSes, because they assume they can just do e.g. I think if we're going to do it for Windows we probably need to do it for everyone. It's probably not the worst thing though - even though environment variables are typically case sensitive on Unixes, I can't think of single case where that actually matters to someone trying to read an environment variable. Worst case, they can use |
I think "cross-platform support" doesn't necessary means "the same script always has the same behavior on every OS". For example, filenames on Windows are case-insensitive, so a script that writes to This PR makes it so that That said, it would be nice to improve documentation and/or issue a warning when |
Correct, it probably doesn't necessarily mean that but that's what we aim for with nushell. We want everything possible to work across MacOS, Linux, and Windows. Some things aren't possible, but I think this one is. I agree with devyn and would prefer this to work the same across platforms. We'd appreciate it if you can please make that one additional change. I think we'd be happy to land this if that happens because many people have been "bitten" by this issue where the path env var doesn't work the same across platforms. |
OK, that's fine with me. |
I've opened a PR on the book that explains the new behavior. |
Thanks. Excited to use this! |
Thanks for this PR, I think this is great addition. One question/problem that I'll submit to everyone is: how should the case preservation interact with the other methods of setting environment variables:
Tagging you as well @sholderbach, since you worked on the recent environment changes. |
@IanManske My vote is for those commands to be case preserving. If a user wants |
I was thinking that as well, but the issue is after, for example, |
hmmm, seems like case preserving would allow both FOO and foo, but I wonder if that would be confusing? |
Personally I think it would be most cross platform to have it use the case of an existing var if there is one. Otherwise |
I think it's supposed to work this way now. I can also do |
I think we should make it an invariant that "$env cannot contains keys like
This does mean that Nushell cannot read both |
As we currently reject duplicate env vars passed to Is the change of implementing the Windows-based case-preserving behavior on the level of Nushell causing problems for folks trying to interact with edge cases on Unix? |
I do worry that being overly strict with it would cause issues for someone trying to do something that is possible on Unix. I don't think it should be impossible to add both to env but I think it should have to be very intentional |
While we do have |
Well, Record cell path updates are normally sensitive I think, but I haven't confirmed that |
Has any thought been put into how this update interacts with nushell/crates/nu-utils/src/sample_config/default_env.nu Lines 65 to 74 in c54d223
nushell/crates/nu-engine/src/env.rs Lines 341 to 347 in c54d223
Which one gets called, maybe both can if it's case-preserving, but I'd hope that record can also benefit from insensitive lookups. |
Currently it doesn't affact ENV_CONVERSIONS at all. We still use case-sensitive comparision to convert to/from the environment. I wonder if that's OK? |
In my perfect world, no one would have to ever know or have to remember what case path needs to be in, whether it is PATH or Path or PaTh or path, all would work everywhere equally. Nushell would know and update the environment appropriately. |
This PR changes
$env
to be case-preserving instead of case-sensitive. That is, it preserves the case of the environment variable when it is first assigned, but subsequent retrieval and update ignores the case.Notably, both
$env.PATH
and$env.Path
can now be used to read or set the environment variable, but child processes will always see the correct case based on the platform.Fixes #11268.
This feature was surprising simple to implement, because most of the infrastructure to support case-insensitive cell path access already exists. The
get
command extracts data using a cell path in a case-insensitive way (!), but accepts a--sensitive
flag. (I think this should be flipped around?)