FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support expanding ~ in $env:PATH when doing command discovery by SteveL-MSFT · Pull Request #11552 · PowerShell/PowerShell · GitHub

Support expanding ~ in $env:PATH when doing command discovery - #11552

Merged
Andrew (anmenaga) merged 3 commits into
PowerShell:masterfrom
SteveL-MSFT:tilde-path
Jan 14, 2020
Merged

Support expanding ~ in $env:PATH when doing command discovery#11552
Andrew (anmenaga) merged 3 commits into
PowerShell:masterfrom
SteveL-MSFT:tilde-path

Conversation

Steve Lee (SteveL-MSFT) commented Jan 10, 2020
edited
Loading

Copy link
Copy Markdown
Member

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Copy link
Copy Markdown
Member

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

Rain Sallow (/u/ta11ow) (vexx32) commented Jan 11, 2020
edited
Loading

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Member Author

Rain Sallow (/u/ta11ow) (@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.

Copy link
Copy Markdown
Collaborator

Steve Lee (@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?

Ilya (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

Copy link
Copy Markdown
Collaborator

I think we need to document the feature.

Copy link
Copy Markdown
Member Author

PoshChan-Bot (@PoshChan) please retry windows

Copy link
Copy Markdown
Collaborator

Steve Lee (@SteveL-MSFT), successfully started retry of PowerShell-CI-Windows

TylerLeonhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Created #11570

Copy link
Copy Markdown

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

Handy links:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL