Reload-MyAliases is now Reload-MyScripts

🔖 https://blog.lksz.me/editing-with-ease/

✏️ Fixed $MyPSScriptRoot typo
 Get-ScopeDepth
🐛 Get-MyAliases didn't work correctly when sub-scoped, fixed the issue
🚚 Reload-MyAliases is now Reload-MyScripts
🐛 Reload-MyScripts loads scripts from $MyPSScriptRoot/profile.d subdir
📝 README updated to reflect change of script name and typo
This commit is contained in:
lksz 2020-09-18 15:41:58 -04:00
parent bb2488e591
commit 06052cfa29
14 changed files with 186 additions and 13 deletions

47
Edit-MyScript.ps1 Normal file
View file

@ -0,0 +1,47 @@
[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
}
Edit-TextFile $ScriptPaths
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
ForEach-Object { . $_.Definition }