PY-71633: Use call operator to execute PS terminal activation.

See `powershell-integration.ps1`.
Call operator is space-proof and more reliable.

Quote from MSDN:

>>>
Call operator `&`

Runs a command, script, or script block. The call operator, also known as the invocation operator, lets you run commands that are stored in variables and represented by strings or script blocks.
>>>

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4#call-operator-

We also add tests: as we do not have Windows tests in the platform, we use PyCharm infra.

Merge-request: KT-MR-19554
Merged-by: Ilya Kazakevich <ilya.kazakevich@jetbrains.com>

cherry pick: 6de26e0d88cff45e30d9354a96b62e8b00c7547a


(cherry picked from commit 39098ea014d5bf7e5d876c9ab9f6e490519490dd)

IJ-CR-152595

GitOrigin-RevId: 6f7ab3b88f7f0a5458953fe1d1783c77bd7d7724
This commit is contained in:
Ilya.Kazakevich
2025-01-09 16:00:35 +01:00
committed by intellij-monorepo-bot
parent 683b622531
commit 2311e23f20

View File

@@ -14,10 +14,10 @@ Get-ChildItem env:_INTELLIJ_FORCE_PREPEND_* | ForEach-Object {
Set-Item -Path "env:\$Name" -Value ($_.Value + $CurValue.Value)
Remove-Item "env:$FullName"
}
$Script = Get-Item "env:JEDITERM_SOURCE" -ErrorAction SilentlyContinue
if ($Script -ne $null) {
Invoke-Expression $Script.Value
# `JEDITERM_SOURCE` is executed in its own scope now. That means, it can only run code, and export env vars. It can't export PS variables.
# It might be better to source it. See MSDN for the difference between "Call operator &" and "Script scope and dot sourcing"
if (($Env:JEDITERM_SOURCE -ne $null) -and (Test-Path $Env:JEDITERM_SOURCE)) {
& $Env:JEDITERM_SOURCE
Remove-Item "env:JEDITERM_SOURCE"
}