From 6b8bd711afdc99849c3e36d2a3210745255f7f0e Mon Sep 17 00:00:00 2001 From: lksz Date: Thu, 27 May 2021 12:47:27 -0400 Subject: [PATCH] Edit-MyScript supports -TypeData editing --- base/Edit-MyScript.ps1 | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/base/Edit-MyScript.ps1 b/base/Edit-MyScript.ps1 index d049607..43f7917 100644 --- a/base/Edit-MyScript.ps1 +++ b/base/Edit-MyScript.ps1 @@ -21,6 +21,32 @@ [Packagesz]::_GetValidValues($wordToComplete,$NotAll,$true) })] [string]$Package, + [ArgumentCompleter({ param ( + $commandName, + $parameterName, + $wordToComplete, + $commandAst, + $fakeBoundParameters + ) + $local:NotAll = $true + if( $fakeBoundParameters.ContainsKey("All") ) { $NotAll = -not $fakeBoundParameters.All } + $( (,( + Get-MyPackages -Force | + ForEach-Object { Join-Path (Join-Path $MyPSScriptRoot $_) $(Join-Path "profile.d" "*.format.ps1xml") } | + Where-Object { Test-Path $_ } | + Get-Item | + ForEach-Object { + "$( $_ | + Select-Object -ExpandProperty Directory | + Select-Object -ExpandProperty Parent | + Select-Object -ExpandProperty Name + ):$($_.Name -replace '\.format\.ps1xml$','')" # -replace ':TypeData$','' + } + )) + ( + [Packagesz]::_GetValidValues($wordToComplete,$NotAll,$true)) + ) | Select-Object -Unique + })] + [string[]]$TypeData, [switch]$ForceImport, [switch]$All, [Parameter(Position = 0, ValueFromRemainingArguments = $true)] @@ -70,6 +96,24 @@ foreach( $local:p in $ScriptName ) { $ScriptPaths += $sp } +foreach( $local:t in $TypeData ) { + $local:pkgName = $t + $local:fileBaseName = 'TypeData' + if( $t.Contains(':') ) { + $pkgName = $t -Split ':' | Select-Object -First 1 + $fileBaseName = $t -Split ':' | Select-Object -Skip 1 -First 1 + } + $fileBaseName = $fileBaseName -replace '\.format\.ps1xml$','' + + Get-Path $( + Join-Path $(Join-Path $EditRootPath $pkgName) $(Join-Path "profile.d" "$fileBaseName.format.ps1xml") + ) | + Where-Object { $_ } | + ForEach-Object { + $ScriptPaths += $_ + } +} + if( -not $ScriptPaths ) { $ScriptPaths += $EditRootPath }