-
Notifications
You must be signed in to change notification settings - Fork 926
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
Correct Nushell source command #4230
Conversation
e36dd77
to
064cf6a
Compare
source "{cargo_home}/env.nu" # For nushell | ||
. "{cargo_home}/env" # For sh/bash/zsh/ash/dash/pdksh | ||
source "{cargo_home}/env.fish" # For fish | ||
source $"($nu.home-path)/.cargo/env.nu" # For nushell |
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.
Note that this is not necessary the $CARGO_HOME
! It's just its default value...
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.
Is there a scenario where $CARGO_HOME is set to a value different than default on a system and a human user will actually read this prompt? Or is it something that's only overriden in CI and such?
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.
@Yethal A human user will actually read the prompt. We allow $CARGO_HOME
to be set to something else beforehand, actually IIRC we have suggested in an earlier note (before the actual installation, see https://github.com/search?q=repo%3Arust-lang%2Frustup+%22This+can+be+modified+with+the%22&type=code) that if you want it to be elsewhere you can set that and return to the installer.
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.
So will it suffice to add a note that if $CARGO_HOME
was overriden then the path will need to be adjusted accordingly?
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.
@Yethal I am still inclined to doing this properly.
For example, you probably can get inspired from this logic:
Lines 469 to 487 in 21d4b27
fn canonical_cargo_home(process: &Process) -> Result<Cow<'static, str>> { | |
let path = process.cargo_home()?; | |
let default_cargo_home = process | |
.home_dir() | |
.unwrap_or_else(|| PathBuf::from(".")) | |
.join(".cargo"); | |
Ok(if default_cargo_home == path { | |
cfg_if! { | |
if #[cfg(windows)] { | |
r"%USERPROFILE%\.cargo".into() | |
} else { | |
"$HOME/.cargo".into() | |
} | |
} | |
} else { | |
path.to_string_lossy().into_owned().into() | |
}) | |
} |
... and figure out a proper way to print the exact path for env.nu
for nushell. Maybe instead of using {cargo_home}
, you can add an extra format argument {cargo_home_nushell}
.
The only detail I don't know is how $nu.home-path
is defined in nushell. However the spirit stays the same: if dirname is ($nu.home-path)/.cargo
you can print source $"($nu.home-path)/.cargo/env.nu"
, otherwise just print out the full path.
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.
Might this be considered a nushell bug? I think they could use std::env::home_dir
since the implementation was fixed in 1.85 (though it won't be undeprecated until 1.87).
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.
What, the fact that environment variables are not parse-time safe? To the best of my knowledge this is by design.
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.
What, the fact that environment variables are not parse-time safe? To the best of my knowledge this is by design.
I believe @ChrisDenton meant that nushell relying on dirs/fn.home_dir.html's behavior could be considered a bug in this case... So you are basically free to ignore the "%USERPROFILE
set to something else" case for now.
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.
No, I mean the fact that it only uses {FOLDERID_Profile}
and doesn't try %USERPROFILE%
first. That would at least mean the behaviour is consistent.
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.
If the behavior was fixed in 1.85 then it might be too early for Nushell since the policy is to stay two versions behind latest stable
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.
AIUI if $CARGO_HOME
is something else then this will get out of sync with other commands.
I believe we should add a more friendly note instead of just using the default value, if the equivalent cannot be achieved in nushell.
It looks like we need something like https://www.nushell.sh/cookbook/foreign_shell_scripts.html but I'm not so sure... cc @LittleJianCH |
38a32d3
to
5f26576
Compare
5f26576
to
8a1f493
Compare
@rami3l I don't think you need the tricks in that link. The canonical way in nushell to resolve dynamic solutions is to place the code that generates in |
An alternative approach would be to place the file in one of nushell's autoload directories so it could be sourced by name only with no relative path |
@alluring-mushroom I agree, and I now think plain substring substitutions would be fine: it's mostly about pretty-printing the absolute path by truncating it after all. |
@rami3l What else do I need to do to get this merged and/or the bug being resolved in any other way? |
@Yethal Sorry for the late reply. I haven't forgotten about this PR, it's just that I've been busy with other stuff for a while. That said, I'd definitely want it to become part of v1.28.2. After a second look, I think although I suggested a string replacement previously, that replacement should not happen when printing the note. Instead, it should happen in the form of a refactored Anyway, the overall outcome I'd like to see is:
PS: If you think that's too much for you, I can offer to fix this patch with your consent. |
So, as a quick summary, this
... and as we must consider Windows in such scenarios now, I suggest using the full paths for nushell and don't bother with |
@Yethal I understand that the command sourcing |
Opposite actually, command sourcing is ok but the generated env.nu is incorrect |
Closing in favor of #4265. |
Nushell uses
$env.HOME
instead of$HOME
syntax for environment variables. However sincesource
is a parser keyword it cannot access environment variables which is why it should use$nu.home-path
insteadAdditionally, the original command will cause nushell to error out on next config evaluation