Skip to content

Commit e65c080

Browse files
fix(functions/reset-cursor): convert cmd variables in path before existence check
1 parent 03af56f commit e65c080

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

Functions.psm1

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
$ErrorActionPreference = 'Stop'
55

6-
#region Test
6+
#region Utils
77
function Test-File {
88
[CmdletBinding()]
99
[OutputType([bool])]
1010
param (
11-
[Parameter(Mandatory)]
11+
[Parameter(Mandatory, ValueFromPipeline)]
1212
[AllowNull()]
1313
[AllowEmptyString()]
1414
[string]$Path
@@ -22,7 +22,7 @@ function Test-Folder {
2222
[CmdletBinding()]
2323
[OutputType([bool])]
2424
param (
25-
[Parameter(Mandatory)]
25+
[Parameter(Mandatory, ValueFromPipeline)]
2626
[AllowNull()]
2727
[AllowEmptyString()]
2828
[string]$Path
@@ -31,9 +31,28 @@ function Test-Folder {
3131
[bool](Test-Path -Path $Path -PathType 'Container' -ErrorAction 'SilentlyContinue')
3232
}
3333
}
34-
#endregion Test
3534

36-
#region Dev
35+
function ConvertFrom-CmdPath {
36+
[CmdletBinding()]
37+
[OutputType([string])]
38+
param (
39+
[Parameter(Mandatory, ValueFromPipeline)]
40+
[AllowNull()]
41+
[AllowEmptyString()]
42+
[string]$Path
43+
)
44+
process {
45+
$powershellPath = $Path
46+
$variables = [regex]::Matches($Path, '%([^%]+)%') | ForEach-Object -Process { $PSItem.Groups[1].Value }
47+
48+
foreach ($variable in $variables) {
49+
$powershellPath = $powershellPath.Replace("%$variable%", [System.Environment]::GetEnvironmentVariable($variable))
50+
}
51+
52+
$powershellPath
53+
}
54+
}
55+
3756
# Compare two cursors which differ only in colors using Unix cmp tool, save the output to a file, then use this function to get only the addresses of the differing bytes
3857
function Get-DiffAddresses {
3958
[CmdletBinding()]
@@ -62,7 +81,7 @@ function Get-DiffAddresses {
6281
Set-Content @Parameters
6382
}
6483
}
65-
#endregion Dev
84+
#endregion Utils
6685

6786
#region Paths
6887
function Initialize-PathsProvider {
@@ -527,7 +546,7 @@ function Set-Cursor {
527546
[string]$Name,
528547

529548
[Parameter(Mandatory)]
530-
[ValidateScript({ Test-File -Path $PSItem })]
549+
[ValidateScript({ $PSItem | ConvertFrom-CmdPath | Test-File })]
531550
[string]$Path
532551
)
533552
begin {

0 commit comments

Comments
 (0)