From 9f08b09c212f12fe671039844c46bf0f5c798ffe Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Wed, 20 Aug 2025 01:08:30 -0500 Subject: [PATCH] added path resolve to add-workspace --- pwsh_workspaces.ps1 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pwsh_workspaces.ps1 b/pwsh_workspaces.ps1 index 22e9275..8beb077 100644 --- a/pwsh_workspaces.ps1 +++ b/pwsh_workspaces.ps1 @@ -47,13 +47,26 @@ function Add-Workspace { [Parameter(Mandatory=$false)] [string]$Path) + # If no path was provided -- get the cwd + # NOTE: This is not a test for whether the path exists, just + # a test about whether the argument was provided. if(-Not $Path) { $Path = Get-Location } - if(Test-Path -Path $Path) { + if(-Not (Test-Path -Path $Path)) { + Write-Output "$Path does not exist, cannot create workspace" + return + } + + # Now we know we have a path that exist. However it + # might be a relative path, so resolve to the full path. + $resolvedPath = Resolve-Path $Path + Write-Output "using resolved path: $resolvedPath" + + if(Test-Path -Path $resolvedPath) { $workspaceSettings = Test-Workspace-Settings - $workspaceEntry = "{0},{1}" -f $Name, $Path + $workspaceEntry = "{0},{1}" -f $Name, $resolvedPath if($workspaceSettings) { if(Test-Workspace-Alias -Alias $Name) { Write-Host "Alias already exists: $Name" @@ -69,9 +82,6 @@ function Add-Workspace { Show-Workspace-Settings } } - else { - Write-Output "$Path does not exist, cannot create workspace" - } } # Set the active workspace using workspace alias