Module loading upgrade

This all started because I wanted the UnixCompleters module and
initialization to move to the base.linux package.

* MyConfig.class modified to load from all modules
* Test-MyModules suppress empty entries
* removed unix entries from base/src/modules.json
+ created base.linux/src/modules.json
This commit is contained in:
lksz 2021-02-18 12:27:50 -05:00
parent 6c19a53518
commit 0e986cfaa7
5 changed files with 32 additions and 21 deletions

View File

@ -1,4 +1,4 @@
Get-Command Import-UnixCompleters -ErrorAction SilentlyContinue | ForEach-Object {
Import-UnixCompleters
Set-UnixCompleter -ShellType Zsh
Set-UnixCompleter -ShellType Bash
}

View File

@ -0,0 +1,5 @@
{
"Unix": [
"Microsoft.PowerShell.UnixCompleters"
]
}

View File

@ -1,17 +1,29 @@
filter _ExpandConfigPath {
$_ | ForEach-Object {
$local:c = Join-Path $(Join-Path $MyPSScriptRoot $(Join-Path '###' 'src')) $_
$c -replace "###","base"
$c -replace "###","*" | Get-Item -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty FullName
} | Select-Object -Unique
}
class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
hidden static [hashtable]$_HardCodedConfigDict = @{
'myconfig' = @($(Join-Path $(Join-Path $PackagePath 'src') 'config.files.json'),
$(Join-Path $(Join-Path $PackagePath 'src') 'config.files.local.json'))
'mymodules' = @($(Join-Path $(Join-Path $PackagePath 'src') 'modules.json'),
$(Join-Path $(Join-Path $PackagePath 'src') 'modules.local.json'))
hidden static [hashtable]$_HardCodedConfigDict = @{
'myconfig' = @('config.files.json','config.files.local.json') | _ExpandConfigPath
'mymodules' = @('modules.json', 'modules.local.json') | _ExpandConfigPath
}
static [hashtable]GetConfigDictionary() {
$local:result = @{}
[MyConfig]::_HardCodedConfigDict.Keys | ForEach-Object { $result[$_] = [MyConfig]::_HardCodedConfigDict[$_] }
[MyConfig]::_HardCodedConfigDict.Keys |
ForEach-Object {
$result[$_] = [MyConfig]::_HardCodedConfigDict[$_]
}
if( Test-Path Function:/_ExpandConfigPath ) { Remove-Item Function:/_ExpandConfigPath }
foreach( $local:jsonSource in $result.myconfig ) {
if( -not ( Test-Path $jsonSource ) ) { continue }
foreach( $local:prop in $(Get-Content $jsonSource | ConvertFrom-Json).PSObject.Properties ) {
$local:props = $(Get-Item $jsonSource | Get-Content | ConvertFrom-Json).PSObject.Properties
foreach( $local:prop in $props ) {
$result[$prop.Name] = $prop.Value
}
}

View File

@ -5,12 +5,13 @@ $local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
if( -not $global:MyModulesWarning -or $Force ) {
$global:MyModulesWarning = @()
}
[MyConfig]::GetConfigPaths('mymodules',$false) |
ForEach-Object {
ForEach-Object {
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
$modules.Always;
$currentSys | ForEach-Object { $modules."$_" } | Where-Object { $_}
} | Where-Object {
$modules.Always
$currentSys | ForEach-Object { $modules."$_" }
} | Where-Object { $_ } | Where-Object {
$local:m = $_
if( $( try {
-not (Get-Module -ListAvailable $m -ErrorAction stop)
@ -21,4 +22,4 @@ if( -not $global:MyModulesWarning -or $Force ) {
} | ForEach-Object {
$global:MyModulesWarning += $_
Write-Warning "Missing module: $_"
}
}

View File

@ -4,11 +4,4 @@
"oh-my-posh",
"posh-git",
"z"
],
"Desktop": [
],
"Unix": [
"Microsoft.PowerShell.UnixCompleters"
]
}
]}