Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

modify PATH env var at startup so that $PSHOME is in front

Fix #4194

…ently running PowerShell

modify PATH env var at startup so that $PSHOME is in front
if (!Platform.IsWindows)
{
pathSeparator = ":";
}
Copy link
Member

Choose a reason for hiding this comment

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

You can use Path.PathSeparator.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

pathSeparator = ":";
}
string pshome = Utils.DefaultPowerShellAppBase;
path.Replace(pathSeparator + pshome, "");
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

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 thought that the PWD got appended to the end of PATH so I didn't want it on both ends, looks like that isn't the case. I'll remove.

}
string pshome = Utils.DefaultPowerShellAppBase;
path.Replace(pathSeparator + pshome, "");
path.Insert(0, pshome + pathSeparator);
Copy link
Member

Choose a reason for hiding this comment

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

We should check if the first path in $env:PATH is pshome, and only insert if it's not. Otherwise, the nested powershell instance will have 2 pshome paths in $env:PATH

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

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 daxian-dbw merged commit d17aaad into PowerShell:master Aug 4, 2017
}
#endif

// put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version
Copy link
Collaborator

@iSazonov iSazonov Aug 6, 2017

Choose a reason for hiding this comment

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

  1. Is this right for other applications?
  2. I would prefer more deterministic [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName. (Related Improve experience for side-by-side versions of PowerShell #4199 . What about Start-PowerShell cmdlet?)

@SteveL-MSFT SteveL-MSFT deleted the powershell-path branch August 6, 2017 20:03
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