Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Jan 10, 2020

PR Summary

The ~ meaning user home path is a commonly used convention. Bash (and compatible shells) expands this automatically (along with other derivatives not covered in this PR). Dotnet global tools sets $env:PATH with a path to the tools starting with ~. In PowerShell, that is treated as a literal so the tools aren't found. Fix is in command discovery, when processing $env:PATH, handle the case where a sub-path starts with ~/ or just contains ~ and expand it to be the user home path.

PR Context

Fix #11531

PR Checklist

@SteveL-MSFT SteveL-MSFT requested a review from anmenaga January 10, 2020 17:56
@SteveL-MSFT SteveL-MSFT added this to the GA-consider milestone Jan 10, 2020
foreach (string directory in tokenizedPath)
{
string tempDir = directory.TrimStart();
if (tempDir.EqualsOrdinalIgnoreCase("~"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only check the very first directory, right? I don't know if tilda can be in the middle...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect that we expand tilde for all elements. There are other applications which add their paths.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intent here is to only handle the beginning case which is the most common case. ~ in the middle doesn't make sense.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daxian-dbw
Copy link
Member

If we do this for PATH, shall we do the same for PSModulePath then?

@vexx32
Copy link
Collaborator

vexx32 commented Jan 11, 2020

There are potentially other PATH values where we might want to apply this as well. I don't recall the exact names off the top of my head, but don't Mac and Linux have PATH-type environment variables that dictate where to look for native library dependencies to load?

}

BeforeAll {
$oldPath = $env:PATH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is tabs here and below. Please fix indentations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the file was mixed formatting, I'll reformat the entire file.


Copy-Item -Path $pwsh -Destination "~/$pwsh2"
$testPath = Join-Path -Path "~" -ChildPath (New-Guid)
New-Item -Path $testPath -ItemType Directory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
New-Item -Path $testPath -ItemType Directory
New-Item -Path $testPath -ItemType Directory > $null

foreach (string directory in tokenizedPath)
{
string tempDir = directory.TrimStart();
if (tempDir.EqualsOrdinalIgnoreCase("~"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect that we expand tilde for all elements. There are other applications which add their paths.

@iSazonov
Copy link
Collaborator

From https://github.com/dotnet/cli/issues/9321 I see that only $HOME works for zsh and MacOs.

@SteveL-MSFT
Copy link
Member Author

@vexx32, you're thinking of LD_LIBRARY_PATH. Similar for PSModulePath, I'm not sure if we want to promote usage of this. This change was specifically to address the dotnet global tool issue.

@vexx32
Copy link
Collaborator

vexx32 commented Jan 13, 2020

@SteveL-MSFT yeah I understand that. My concern is simply that we will now have two separate ways we handle the one "kind" of environment variable.

It's certainly not desirable to promote this oddity too much, I'll agree, but I wonder whether it's better / simpler to be consistent here and have a single way of handling at least initial path resolution for paths in these variables?

@iSazonov iSazonov added CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Documentation Needed in this repo Documentation is needed in this repo labels Jan 13, 2020
@iSazonov
Copy link
Collaborator

I think we need to document the feature.

@SteveL-MSFT
Copy link
Member Author

@PoshChan please retry windows

@PoshChan
Copy link
Collaborator

@SteveL-MSFT, successfully started retry of PowerShell-CI-Windows

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but maybe open an issue to support Tilda in other PATH-like variables.

@SteveL-MSFT
Copy link
Member Author

Created #11570

@anmenaga anmenaga merged commit de2d34b into PowerShell:master Jan 14, 2020
@daxian-dbw daxian-dbw modified the milestones: GA-approved, 7.0.0-rc.2 Jan 14, 2020
@ghost
Copy link

ghost commented Jan 16, 2020

🎉v7.0.0-rc.2 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Documentation Needed in this repo Documentation is needed in this repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle ~ in PATH

8 participants