-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ensure running powershell within PowerShell starts instance of currently running PowerShell
#4481
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
Conversation
…ently running PowerShell modify PATH env var at startup so that $PSHOME is in front
| if (!Platform.IsWindows) | ||
| { | ||
| pathSeparator = ":"; | ||
| } |
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.
You can use Path.PathSeparator.
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.
ok
| pathSeparator = ":"; | ||
| } | ||
| string pshome = Utils.DefaultPowerShellAppBase; | ||
| path.Replace(pathSeparator + pshome, ""); |
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.
Why is this needed?
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.
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); |
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.
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
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.
ok
daxian-dbw
left a comment
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.
LGTM
| } | ||
| #endif | ||
|
|
||
| // put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version |
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 this right for other applications?
- I would prefer more deterministic
[System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName. (Related Improve experience for side-by-side versions of PowerShell #4199 . What aboutStart-PowerShellcmdlet?)
modify PATH env var at startup so that $PSHOME is in front
Fix #4194