Introducing Packages
Major Overhaul with Breaking Changes split into packaged, default behavior moved into 'base' package each package has a json package description file with criteria for loading Modified Setup-Profile to refer to 'base' package path for auto loading moved Linux aliases and command to 'base.linux' package created 'docker' package to address docker supported systems modified Get-MyScripts, Edit-MyScripts and Reload-MyScripts accordingly. Dropped -System and sys.*, package json conditions will take care of it. Supplied command to create/edit package json files: - New-MyPackage - Add-PackageCondition - Set-MyPackage
This commit is contained in:
parent
80a488484b
commit
42b39f4e25
83 changed files with 505 additions and 130 deletions
32
base/profile.d/Docker.class.ps1
Normal file
32
base/profile.d/Docker.class.ps1
Normal file
|
@ -0,0 +1,32 @@
|
|||
class DockerContainer { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
|
||||
$local:possibleValues = $(
|
||||
docker ps -a --no-trunc --format "{{.Names}}"
|
||||
)
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||
}
|
||||
|
||||
[String[]] GetValidValues() {
|
||||
return [DockerContainer]::_GetValidValues('',$true)
|
||||
}
|
||||
}
|
||||
|
||||
class DockerComposeDirs { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
|
||||
$local:possibleValues = $(
|
||||
Get-ChildItem -Directory -Depth 3 |
|
||||
Where-Object { $_ |
|
||||
Get-ChildItem -Include 'docker-compose.y*l' |
|
||||
Where-Object Extension -in '.yml','.yaml'
|
||||
} | ForEach-Object {
|
||||
$_.FullName.Replace($(Join-Path $PWD ""),'')
|
||||
}
|
||||
)
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||
}
|
||||
|
||||
[String[]] GetValidValues() {
|
||||
return [DockerComposeDirs]::_GetValidValues('',$true)
|
||||
}
|
||||
}
|
||||
|
21
base/profile.d/FromPowerShellCookbook.ps1
Normal file
21
base/profile.d/FromPowerShellCookbook.ps1
Normal file
|
@ -0,0 +1,21 @@
|
|||
# PowerShell Cookbook has a lot of code there, I'm only interested in
|
||||
# the Add-ObjectCollector which adds an overloaded Out-Default version,
|
||||
# which stores a history of output objects.
|
||||
# One major problem with loading this from the module, is that when the
|
||||
# module is removed the shell BREAKS.
|
||||
#
|
||||
# The code below, makes sure the module is removed, and then imports
|
||||
# only the Add-ObjectCollector code from it.
|
||||
# All I really want is the Out-Default function created by
|
||||
# Add-ObjectCollector, and so, I'll also remove the function once done.
|
||||
|
||||
if( Get-Module PowerShellCookbook ) {
|
||||
Remove-Module PowerShellCookbook
|
||||
|
||||
Import-Module PowerShellCookbook -Cmdlet Add-ObjectCollector
|
||||
}
|
||||
#
|
||||
. Get-Command Add-ObjectCollector -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
Add-ObjectCollector
|
||||
Get-Item function:/Add-ObjectCollector | Remove-Item
|
||||
}
|
21
base/profile.d/FunctionName.class.ps1
Normal file
21
base/profile.d/FunctionName.class.ps1
Normal file
|
@ -0,0 +1,21 @@
|
|||
class FunctionName { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
|
||||
$local:possibleValues = Get-Command -Type Function | Select-Object -ExpandProperty Name
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||
}
|
||||
static [String[]] _GetValidValues([string]$wordToComplete,[switch]$Strict) {
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $(Get-Command -Type Function | Select-Object -ExpandProperty Name) -Strict:$Strict)
|
||||
# $local:possibleValues =
|
||||
# if( $wordToComplete ) {
|
||||
# $possibleValues = $possibleValues | Where-Object { $_ -match $wordToComplete }
|
||||
# if( -not $strict -and ($wordToComplete -notin $possibleValues) ) {
|
||||
# $possibleValues = $( $wordToComplete; $possibleValues )
|
||||
# }
|
||||
# }
|
||||
# return $possibleValues
|
||||
}
|
||||
|
||||
[String[]] GetValidValues() {
|
||||
return [FunctionName]::_GetValidValues('',$true)
|
||||
}
|
||||
}
|
61
base/profile.d/MyConfig.class.ps1
Normal file
61
base/profile.d/MyConfig.class.ps1
Normal file
|
@ -0,0 +1,61 @@
|
|||
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'))
|
||||
}
|
||||
|
||||
static [hashtable]GetConfigDictionary() {
|
||||
$local:result = @{}
|
||||
[MyConfig]::_HardCodedConfigDict.Keys | ForEach-Object { $result[$_] = [MyConfig]::_HardCodedConfigDict[$_] }
|
||||
foreach( $local:jsonSource in $result.myconfig ) {
|
||||
if( -not ( Test-Path $jsonSource ) ) { continue }
|
||||
foreach( $local:prop in $(Get-Content $jsonSource | ConvertFrom-Json).PSObject.Properties ) {
|
||||
$result[$prop.Name] = $prop.Value
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
static [string[]] GetConfigPaths([string[]]$ConfigNames,[switch]$Force) {
|
||||
$local:configDirectory = [MyConfig]::GetConfigDictionary()
|
||||
$local:result = [string[]]@()
|
||||
$local:flat = $false
|
||||
while(-not $flat) {
|
||||
$flat = $true
|
||||
$ConfigNames += $ConfigNames | ForEach-Object {
|
||||
$configDirectory[$_]
|
||||
} | Where-Object { $_ -match '^#[\w-\.]+$' } | ForEach-Object {
|
||||
$_.Substring(1)
|
||||
} | Where-Object { $_ -notin $ConfigNames } | ForEach-Object {
|
||||
$flat = false; $_;
|
||||
}
|
||||
}
|
||||
|
||||
$local:flatConfigList = $ConfigNames | ForEach-Object {
|
||||
$configDirectory[$_]
|
||||
} | Where-Object { $_ -notmatch '^#[\w-\.]+$' }
|
||||
|
||||
$local:exists = $false;
|
||||
$local:first = $null
|
||||
foreach( $local:configPath in $flatConfigList ) {
|
||||
if( -not $first ) { $first = $configPath }
|
||||
if( $Force -or (Test-Path $configPath) ) {
|
||||
$result += Get-Path $configPath
|
||||
$exists = $true
|
||||
}
|
||||
}
|
||||
if( -not $exists -and -not $Force ) {
|
||||
$result += $first
|
||||
}
|
||||
return $result
|
||||
}
|
||||
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
|
||||
$local:possibleValues = [MyConfig]::GetConfigDictionary().Keys
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||
}
|
||||
|
||||
[String[]] GetValidValues() {
|
||||
return [MyConfig]::_GetValidValues('',$true)
|
||||
}
|
||||
}
|
16
base/profile.d/MyScript.class.ps1
Normal file
16
base/profile.d/MyScript.class.ps1
Normal file
|
@ -0,0 +1,16 @@
|
|||
class MyScript { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$CurrentOnly,[bool]$Strict) {
|
||||
$local:possibleValues = $(
|
||||
Get-MyPackages -ReturnFullPath -IncludeRoot -Force:$(-not $CurrentOnly) |
|
||||
Get-ChildItem -Filter '*.ps1' |
|
||||
Select-Object -ExpandProperty FullName | ForEach-Object {
|
||||
$_ -replace '\.ps1$','' -replace "$($MyPSScriptRoot -replace '\\',"\\")[/\\]",''
|
||||
}
|
||||
)
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||
}
|
||||
|
||||
[String[]] GetValidValues() {
|
||||
return [MyScript]::_GetValidValues('',$false,$true)
|
||||
}
|
||||
}
|
2
base/profile.d/Style.ps1
Normal file
2
base/profile.d/Style.ps1
Normal file
|
@ -0,0 +1,2 @@
|
|||
Get-Command Set-PSReadLineKeyHandler | ForEach-Object { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete }
|
||||
Get-Command Set-Theme -ErrorAction SilentlyContinue | ForEach-Object { Set-Theme Paradox }
|
24
base/profile.d/Test-MyModules.ps1
Normal file
24
base/profile.d/Test-MyModules.ps1
Normal file
|
@ -0,0 +1,24 @@
|
|||
param([switch]$Force)
|
||||
|
||||
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
||||
|
||||
if( -not $global:MyModulesWarning -or $Force ) {
|
||||
$global:MyModulesWarning = @()
|
||||
}
|
||||
[MyConfig]::GetConfigPaths('mymodules',$false) |
|
||||
ForEach-Object {
|
||||
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
|
||||
$modules.Always;
|
||||
$currentSys | ForEach-Object { $modules."$_" } | Where-Object { $_}
|
||||
} | Where-Object {
|
||||
$local:m = $_
|
||||
if( $( try {
|
||||
-not (Get-Module -ListAvailable $m -ErrorAction stop)
|
||||
} catch { $true }
|
||||
)) {
|
||||
$m -notin $global:MyModulesWarning
|
||||
}
|
||||
} | ForEach-Object {
|
||||
$global:MyModulesWarning += $_
|
||||
Write-Warning "Missing module: $_"
|
||||
}
|
4
base/profile.d/UnixCompleters.ps1
Normal file
4
base/profile.d/UnixCompleters.ps1
Normal file
|
@ -0,0 +1,4 @@
|
|||
Get-Command Import-UnixCompleters -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
Import-UnixCompleters
|
||||
Set-UnixCompleter -ShellType Zsh
|
||||
}
|
3
base/profile.d/classes.ps1
Normal file
3
base/profile.d/classes.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
. Invoke-Expression ". $(Join-Path $(Join-Path $PackagePath 'src') 'SystemName.class.inc.ps1')"
|
||||
. Invoke-Expression ". $(Join-Path $(Join-Path $PackagePath 'src') 'Packagesz.class.inc.ps1')"
|
||||
|
3
base/profile.d/env.local.ps1.template
Normal file
3
base/profile.d/env.local.ps1.template
Normal file
|
@ -0,0 +1,3 @@
|
|||
# $env:DOMAIN_NAME='example.com'
|
||||
#
|
||||
# $env:EDITOR='/usr/bin/nvim'
|
1
base/profile.d/env.ps1
Normal file
1
base/profile.d/env.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
$env:SZ_SKIP_DEFAULT_SHELL = 1
|
1
base/profile.d/load-z.ps1
Normal file
1
base/profile.d/load-z.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Get-Module -ListAvailable z | Import-Module
|
Loading…
Add table
Add a link
Reference in a new issue