got Use-UE-Workspace creating a new session to install ushell correctly

This commit is contained in:
Matt Brown 2025-01-27 09:50:58 -06:00
parent aacd09eaa9
commit bb2ab60ac1

View File

@ -1,4 +1,4 @@
### workspace ### ### Workspace ###
$workspaceSettings = "$env:USERPROFILE\.pwsh_workspace_settings.txt" $workspaceSettings = "$env:USERPROFILE\.pwsh_workspace_settings.txt"
$activeWorkspace = "" $activeWorkspace = ""
@ -212,20 +212,27 @@ function Use-Active-UE-Workspace {
} }
} }
# Basically like Use-Active-UE-Workspace but this function # Creates a new powershell session then navigates to the
# does the additional work of looking up and setting the # workspace path and imports the ushell module. Creating a
# active workspace based on the provided workspace name/alias # new session is needed so that when you switch UE workspaces,
# ushell is installed with the correct context of the workspace.
function Use-UE-Workspace { function Use-UE-Workspace {
param([Parameter(Mandatory=$true)] param([Parameter(Mandatory=$true)]
[string]$Name) [string]$Name,
[Parameter(Mandatory=$false)]
[bool]$NewSession = $true)
if($NewSession) {
New-UE-Session -Name $Name
}
else {
Use-Workspace -Name $Name Use-Workspace -Name $Name
$location = Get-Location $location = Get-Location
$resolvedCurrentLocation = Resolve-Path $location $resolvedCurrentLocation = Resolve-Path $location
$resolvedActiveWorkspace = Resolve-Path $global:activeWorkspace $resolvedActiveWorkspace = Resolve-Path $global:activeWorkspace
# check that we are in the expected place then proceed # Check that we are in the expected place then proceed
if($resolvedCurrentLocation.ProviderPath && $resolvedActiveWorkspace.ProviderPath) { if($resolvedCurrentLocation.ProviderPath -eq $resolvedActiveWorkspace.ProviderPath) {
if(Test-Active-Workspace) { if(Test-Active-Workspace) {
$ushellRelativePath = "Engine\Extras\ushell\ushell.psm1" $ushellRelativePath = "Engine\Extras\ushell\ushell.psm1"
$ushellPath = "{0}\{1}" -f $resolvedActiveWorkspace, $ushellRelativePath $ushellPath = "{0}\{1}" -f $resolvedActiveWorkspace, $ushellRelativePath
@ -241,4 +248,18 @@ function Use-UE-Workspace {
else { else {
Write-Error "Did not correctly switch to workspace $Name" Write-Error "Did not correctly switch to workspace $Name"
} }
}
} }
function New-UE-Session {
param([Parameter(Mandatory=$true)]
[string]$Name)
if(Test-Workspace-Alias -Alias $Name) {
Start-Process pwsh -ArgumentList @("-NoExit", "-Command", "& {. $PROFILE; Use-UE-Workspace -Name $Name -NewSession `$false`}")
Stop-Process -Id $PID
}
else {
Write-Host "Alias $Name does not exist, not creating new session"
}
}
### Workspace ###