1
0
Derivar 0
PowerShell_Scripts/Edit-MyScript.ps1
lksz ae07e06c27 Setup-Profile and co.
Setup-Profile included, read all about it at
https://blog.lksz.me/the-profile-and-setting-it-up
When running Edit-MyScript without parameters, the $MyPSScriptRoot path
will be sent (editing the directory)
Added ability to edit scripts with Edit-MyPrfiles, making editing
profiles alongside scripts easy.
2020-09-25 01:30:21 -04:00

51 linhas
1,3 KiB
PowerShell

[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[FunctionName]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ImportFunction,
[switch]$ForceImport,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[MyScript]::_GetValidValues($wordToComplete,$false)
})]
[string[]]$ScriptName
)
$local:ScriptPaths = @()
foreach( $local:p in $ImportFunction ) {
$local:f = Get-Command $p -Type Function
if( $f ) {
$local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
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 ) {
$local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
$ScriptPaths += $sp
}
if( -not $ScriptPaths ) {
$ScriptPaths += $MyPSScriptRoot
}
Edit-TextFile $ScriptPaths
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
ForEach-Object { . $_.Definition }