2020-09-18 19:41:58 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param(
|
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
|
|
|
[FunctionName]::_GetValidValues($wordToComplete,$true)
|
|
|
|
})]
|
|
|
|
[string[]]$ImportFunction,
|
2020-10-02 16:45:04 +00:00
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
2020-11-25 05:46:33 +00:00
|
|
|
$local:NotAll = $true
|
|
|
|
if( $fakeBoundParameters.ContainsKey("All") ) { $NotAll = -not $fakeBoundParameters.All }
|
|
|
|
[Packagesz]::_GetValidValues($wordToComplete,$NotAll,$true)
|
2020-10-02 16:45:04 +00:00
|
|
|
})]
|
2020-11-25 05:46:33 +00:00
|
|
|
[string]$Package,
|
2021-05-27 16:47:27 +00:00
|
|
|
[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,
|
2020-09-18 19:41:58 +00:00
|
|
|
[switch]$ForceImport,
|
2020-11-25 05:46:33 +00:00
|
|
|
[switch]$All,
|
2020-09-18 19:41:58 +00:00
|
|
|
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
|
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
2020-11-25 05:46:33 +00:00
|
|
|
$local:NotAll = $true
|
|
|
|
$local:Pkg = [string]::Empty
|
|
|
|
if( $fakeBoundParameters.ContainsKey("All") ) { $NotAll = -not $fakeBoundParameters.All }
|
|
|
|
if( $fakeBoundParameters.ContainsKey("Package") ) { $Pkg = Join-Path $fakeBoundParameters.Package '' }
|
|
|
|
$local:possibleValues = [MyScript]::_GetValidValues($wordToComplete,$NotAll,$true)
|
|
|
|
if( $Pkg ) {
|
|
|
|
$possibleValues = $possibleValues |
|
|
|
|
Where-Object { $_ -match "^$Pkg" } |
|
|
|
|
ForEach-Object { $_.Replace($Pkg,'') }
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-11-25 05:46:33 +00:00
|
|
|
|
2020-10-02 16:45:04 +00:00
|
|
|
$possibleValues
|
2020-09-18 19:41:58 +00:00
|
|
|
})]
|
2020-12-05 23:18:12 +00:00
|
|
|
[string[]]$ScriptName,
|
|
|
|
[switch]$WaitNotRequired = $env:WAIT_NOT_REQUIRED
|
2020-09-18 19:41:58 +00:00
|
|
|
)
|
|
|
|
|
2020-10-02 16:45:04 +00:00
|
|
|
$local:EditRootPath=$MyPSScriptRoot
|
2020-11-25 05:46:33 +00:00
|
|
|
if( $Package ) {
|
|
|
|
$EditRootPath = Join-Path $EditRootPath $Package
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-09-18 19:41:58 +00:00
|
|
|
$local:ScriptPaths = @()
|
|
|
|
foreach( $local:p in $ImportFunction ) {
|
2021-04-27 16:04:12 +00:00
|
|
|
$local:f = Get-Command -ListImported $p -Type Function
|
2020-09-18 19:41:58 +00:00
|
|
|
if( $f ) {
|
2020-10-02 16:45:04 +00:00
|
|
|
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
2020-09-18 19:41:58 +00:00
|
|
|
if( $ForceImport -or -not (Test-Path $sp) ) {
|
|
|
|
Export-FunctionSource $p -NoHeader > $sp
|
|
|
|
} elseif ( -not $ForceImport ) {
|
|
|
|
throw "$p already exists in Script, to import the function again, use the -Force"
|
|
|
|
}
|
|
|
|
$ScriptPaths += $sp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach( $local:p in $ScriptName ) {
|
2020-10-02 16:45:04 +00:00
|
|
|
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
2020-09-18 19:41:58 +00:00
|
|
|
$ScriptPaths += $sp
|
|
|
|
}
|
|
|
|
|
2021-05-27 16:47:27 +00:00
|
|
|
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 += $_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 05:04:05 +00:00
|
|
|
if( -not $ScriptPaths ) {
|
2020-10-02 16:45:04 +00:00
|
|
|
$ScriptPaths += $EditRootPath
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach( $local:p in $ScriptPaths ) {
|
|
|
|
$local:parentPath = Split-Path -Parent $p;
|
|
|
|
if( -not (Test-Path $p) -and -not (Test-Path $parentPath) ) {
|
2020-10-03 20:17:11 +00:00
|
|
|
Write-Verbose "Creating missing path $parentPath..."
|
|
|
|
New-Item -Type Directory $parentPath
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-09-25 05:04:05 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 18:06:17 +00:00
|
|
|
$local:sw = [System.Diagnostics.Stopwatch]::StartNew();
|
2021-05-12 13:29:18 +00:00
|
|
|
Edit-TextFile -Path $ScriptPaths
|
2020-11-09 18:06:17 +00:00
|
|
|
$sw.Stop();
|
|
|
|
|
2021-05-12 13:29:18 +00:00
|
|
|
if( $sw.Elapsed.TotalSeconds -lt 3 ) {
|
|
|
|
Write-Host -ForegroundColor DarkGreen "When done editing, you might want to run '. Reload-MyScripts'"
|
|
|
|
return
|
2020-11-09 18:06:17 +00:00
|
|
|
}
|
2020-09-18 19:41:58 +00:00
|
|
|
|
2021-04-27 16:04:12 +00:00
|
|
|
Get-Command -ListImported Reload-MyScripts -ErrorAction SilentlyContinue |
|
2020-09-18 19:41:58 +00:00
|
|
|
ForEach-Object { . $_.Definition }
|