Skip to content

allow users to access $env.path in a case-insensitive manner - #11268

Closed
fdncred wants to merge 5 commits into
nushell:mainfrom
fdncred:make_env_path_case_insensitive
Closed

fdncred wants to merge 5 commits into
nushell:mainfrom
fdncred:make_env_path_case_insensitive

Conversation

@fdncred

@fdncred fdncred commented Dec 8, 2023

Copy link
Copy Markdown
Contributor

Description

Nushell has never been able to handle PATH on Windows or Path on *nix, because in those two use cases, they do not exist and it's actually reversed. Windows (most) always wants to see $env.Path and MacOS and Linux want to see $env.PATH. This lead to a bunch of scripts checking the OS to determine if they should look at PATH or Path. This change allows you to $env.Path, $env.PATH, $env.path, $env.PaTh on any OS, effectively making this access case-insensitive.

image

I'm not sure this change is in the right place, but it works. I'm looking for reviewers to point out what's wrong with this or a better way to do it. It seems a little hack-ish to me.

I initially tried to hard code anything to PATH but that ended up breaking things an giving me two PATH env variables on Windows. It was very weird to have 2 of the same name env var. To top it off, they had slightly different data as well. So, I took the path of least resistance, which means Windows is always really stored as Path and MacOS/Linux is always stored as PATH.

User-Facing Changes

Tests + Formatting

After Submitting

@fdncred

fdncred commented Dec 11, 2023

Copy link
Copy Markdown
Contributor Author

Not sure how I'm doing this but on linux PATH is getting added twice. One has the right values, one has the wrong ones and the tests are failing because of this (I think).
image

@fdncred

fdncred commented Dec 11, 2023

Copy link
Copy Markdown
Contributor Author

I think I finally cracked this nut. More of a root-canal than I expected but it seems to work.

@raggi

raggi commented Dec 28, 2023

Copy link
Copy Markdown

I think fixing #11154 is a much better idea, otherwise the project could end up maintaining not only two odd system behaviors, but also the interpolation of historical choices such as this as well. If #11154 is fixed, all users could use $env.PATH, as they do in all other shells, including other shells on Windows.

@raggi

raggi commented Dec 28, 2023

Copy link
Copy Markdown

For consideration: #11432

@amtoine amtoine added the platform:windows Issues which are specific to Windows label Dec 28, 2023
@fdncred fdncred removed the platform:windows Issues which are specific to Windows label Dec 28, 2023
@fdncred

fdncred commented Dec 28, 2023

Copy link
Copy Markdown
Contributor Author

This is not a windows-only change. It makes $env.PATH case insensitive across platforms.

@amtoine

amtoine commented Dec 28, 2023

Copy link
Copy Markdown
Member

case-insensitive env in other systems still sounds strange to me 🤔
making that windows only maybe?

@fdncred

fdncred commented Dec 28, 2023

Copy link
Copy Markdown
Contributor Author

@amtoine I think it sounds strange to you because you only live in Linux.

If #11154 is fixed, all users could use $env.PATH, as they do in all other shells, including other shells on Windows.

This is true but it's basically saying, let's do everything the Linux way. It also means that you can't have $env.path on Windows and Linux or MacOS. With your PR, it would work on Windows but not anywhere else. So, therefore, scripts would not be cross-platform because you'd have to be very conscious about how you deal with path. My PR doesn't care. I'm not saying all my changes are 100% right, but I'm saying I like the concept of being able to ignore the case everywhere better.

@amtoine

amtoine commented Dec 28, 2023

Copy link
Copy Markdown
Member

@amtoine I think it sounds strange to you because you only live in Linux.

yup, completely 😋
i was not talking for Windows 😉

a related comment i think

@yizhepku

Copy link
Copy Markdown
Contributor

I don't like the idea of making only $env.path case-insensitive. It feels unintuitive. Either all environment variables should be case-insensitive, or none at all. I like @raggi's proposal better.

It also means that you can't have $env.path on Windows and Linux or MacOS. With your PR, it would work on Windows but not anywhere else.

What if instead of trying to make $env.path work on Linux, we make it break on Windows? We can guard against any attempt to write to $env.path or $env.Path and throw an error, telling the user to write to $env.PATH instead.

@fdncred

fdncred commented Apr 27, 2024

Copy link
Copy Markdown
Contributor Author

I'm also fine with the other PR like this one. Someone has to finish it though.

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.

4 participants