Skip to content

Commit

Permalink
fix(functions/reset-cursor): convert cmd variables in path before exi…
Browse files Browse the repository at this point in the history
…stence check
  • Loading branch information
SunsetTechuila committed May 9, 2024
1 parent 03af56f commit e65c080
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions Functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

$ErrorActionPreference = 'Stop'

#region Test
#region Utils
function Test-File {
[CmdletBinding()]
[OutputType([bool])]
param (
[Parameter(Mandatory)]
[Parameter(Mandatory, ValueFromPipeline)]
[AllowNull()]
[AllowEmptyString()]
[string]$Path
Expand All @@ -22,7 +22,7 @@ function Test-Folder {
[CmdletBinding()]
[OutputType([bool])]
param (
[Parameter(Mandatory)]
[Parameter(Mandatory, ValueFromPipeline)]
[AllowNull()]
[AllowEmptyString()]
[string]$Path
Expand All @@ -31,9 +31,28 @@ function Test-Folder {
[bool](Test-Path -Path $Path -PathType 'Container' -ErrorAction 'SilentlyContinue')
}
}
#endregion Test

#region Dev
function ConvertFrom-CmdPath {
[CmdletBinding()]
[OutputType([string])]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[AllowNull()]
[AllowEmptyString()]
[string]$Path
)
process {
$powershellPath = $Path
$variables = [regex]::Matches($Path, '%([^%]+)%') | ForEach-Object -Process { $PSItem.Groups[1].Value }

foreach ($variable in $variables) {
$powershellPath = $powershellPath.Replace("%$variable%", [System.Environment]::GetEnvironmentVariable($variable))
}

$powershellPath
}
}

# 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
function Get-DiffAddresses {
[CmdletBinding()]
Expand Down Expand Up @@ -62,7 +81,7 @@ function Get-DiffAddresses {
Set-Content @Parameters
}
}
#endregion Dev
#endregion Utils

#region Paths
function Initialize-PathsProvider {
Expand Down Expand Up @@ -527,7 +546,7 @@ function Set-Cursor {
[string]$Name,

[Parameter(Mandatory)]
[ValidateScript({ Test-File -Path $PSItem })]
[ValidateScript({ $PSItem | ConvertFrom-CmdPath | Test-File })]
[string]$Path
)
begin {
Expand Down

0 comments on commit e65c080

Please sign in to comment.