4 Commits

Author SHA1 Message Date
  lksz 1792bb23a1 Introducing Packages 5 months ago
  lksz@work 80a488484b Set-EnvVariable + minor fix to SystemName 5 months ago
  Gal Szkolnik 25ec753675 Renamed dl into dlogs. 5 months ago
  lksz 1bef8ca119 Improved Export-FunctionSource + some Docker fixes 5 months ago
86 changed files with 580 additions and 147 deletions
Unified View
  1. +0
    -8
      Get-MyScript.ps1
  2. +4
    -4
      README.md
  3. +0
    -88
      Reload-MyScripts.ps1
  4. +0
    -0
      base.linux/Get-PlexInfo.ps1
  5. +0
    -0
      base.linux/Invoke-ViaAnsible.ps1
  6. +0
    -0
      base.linux/Pull-ViaAnsible.ps1
  7. +6
    -0
      base.linux/Set-EnvVariable.ps1
  8. +0
    -0
      base.linux/Update-ArchOSz.ps1
  9. +0
    -0
      base.linux/Update-OSz.ps1
  10. +0
    -0
      base.linux/Update-UbuntuOSz.ps1
  11. +0
    -0
      base.linux/Update-ViaAnsible.ps1
  12. +16
    -0
      base.linux/_.package.json
  13. +0
    -0
      base.linux/ls.ps1
  14. +0
    -0
      base.linux/sranger.ps1
  15. +0
    -0
      base.linux/sz-df.ps1
  16. +0
    -0
      base.linux/sz-du.ps1
  17. +0
    -0
      base.linux/sz-rsync.ps1
  18. +0
    -0
      base.linux/txm.ps1
  19. +11
    -0
      base.win/Set-EnvVariable.ps1
  20. +16
    -0
      base.win/_.package.json
  21. +21
    -0
      base/Add-PackageCondition.ps1
  22. +0
    -0
      base/Aliases/dcedit.ps1
  23. +0
    -0
      base/Aliases/dco.ps1
  24. +0
    -0
      base/Aliases/dps.ps1
  25. +0
    -0
      base/Aliases/edit
  26. +0
    -0
      base/Aliases/l.ps1
  27. +0
    -0
      base/Aliases/ll.ps1
  28. +0
    -0
      base/Aliases/sz-update.ps1
  29. +0
    -0
      base/Aliases/vi
  30. +0
    -0
      base/Aliases/vidc.ps1
  31. +0
    -0
      base/Aliases/vim
  32. +0
    -0
      base/ConvertFrom-Base64.ps1
  33. +0
    -0
      base/Edit-MyConfig.ps1
  34. +0
    -0
      base/Edit-MyProfiles.ps1
  35. +17
    -7
      base/Edit-MyScript.ps1
  36. +0
    -0
      base/Edit-TextFile.ps1
  37. +21
    -0
      base/Get-MyPackages.ps1
  38. +44
    -0
      base/Get-MyScript.ps1
  39. +0
    -0
      base/Get-Path.ps1
  40. +0
    -0
      base/Get-PossibleArguments.ps1
  41. +0
    -0
      base/Get-Profiles.ps1
  42. +0
    -0
      base/Get-ScopeDepth.ps1
  43. +0
    -0
      base/Invoke-Sudo.ps1
  44. +5
    -0
      base/New-MyPackage.ps1
  45. +111
    -0
      base/Reload-MyScripts.ps1
  46. +38
    -0
      base/Set-MyPackage.ps1
  47. +18
    -3
      base/Setup-Profile.ps1
  48. +0
    -0
      base/Stop-ProcessTree.ps1
  49. +5
    -0
      base/_.package.json
  50. +32
    -0
      base/profile.d/Docker.class.ps1
  51. +0
    -0
      base/profile.d/FromPowerShellCookbook.ps1
  52. +0
    -0
      base/profile.d/FunctionName.class.ps1
  53. +4
    -4
      base/profile.d/MyConfig.class.ps1
  54. +16
    -0
      base/profile.d/MyScript.class.ps1
  55. +0
    -0
      base/profile.d/Style.ps1
  56. +0
    -0
      base/profile.d/Test-MyModules.ps1
  57. +0
    -0
      base/profile.d/UnixCompleters.ps1
  58. +3
    -0
      base/profile.d/classes.ps1
  59. +0
    -0
      base/profile.d/env.local.ps1.template
  60. +0
    -0
      base/profile.d/env.ps1
  61. +0
    -0
      base/profile.d/load-z.ps1
  62. +97
    -0
      base/src/Packagesz.class.inc.ps1
  63. +1
    -0
      base/src/SystemName.class.inc.ps1
  64. +4
    -2
      base/src/config.files.json
  65. +0
    -0
      base/src/modules.json
  66. +0
    -0
      base/src/smartsudo.inc.ps1
  67. +0
    -3
      dcc.ps1
  68. +0
    -1
      dcdown.ps1
  69. +0
    -10
      dcup.ps1
  70. +16
    -2
      docker/Edit-DockerCompose.ps1
  71. +0
    -0
      docker/Get-DockerProcess.ps1
  72. +14
    -0
      docker/_.package.json
  73. +14
    -0
      docker/dcc.ps1
  74. +18
    -0
      docker/dcdown.ps1
  75. +0
    -0
      docker/dcl.ps1
  76. +0
    -0
      docker/dcll.ps1
  77. +0
    -0
      docker/dcr.ps1
  78. +0
    -0
      docker/dcre.ps1
  79. +0
    -0
      docker/dcreup.ps1
  80. +28
    -0
      docker/dcup.ps1
  81. +0
    -0
      docker/dcx.ps1
  82. +0
    -0
      docker/di.ps1
  83. +0
    -0
      docker/dll.ps1
  84. +0
    -0
      docker/dlogs.ps1
  85. +0
    -0
      docker/dx.ps1
  86. +0
    -15
      profile.d/MyScript.class.ps1

+ 0
- 8
Get-MyScript.ps1 View File

@@ -1,8 +0,0 @@
[CmdletBinding()]param(
[string]$Filter,
[switch]$NamesOnly
)
$local:rVal = [MyScript]::_GetValidValues($Filter,$true)
if( $NamesOnly ) { return $rVal }
return $rVal | ForEach-Object { Join-Path $MyPSScriptRoot "$_`.ps1" }


+ 4
- 4
README.md View File

@@ -13,14 +13,14 @@ iwr https://lksz.me/pwsz | iex
``` ```


This sets up the `$PROFILE` file, and initilizes the default dir `$MyPSScriptRoot` with a git clone of this repo. This sets up the `$PROFILE` file, and initilizes the default dir `$MyPSScriptRoot` with a git clone of this repo.
The `https://lksz.me/pwsz` actually points to the [`Setup-Profile.ps1`](Setup-Profile.ps1) script, which means, that after you have the `Scripts` directory setup, you can call `Setup-Profile` to update the `$PROFILE` after the `Setup-Profile.ps1` has been modified (or updated via `git pull`).
The `https://lksz.me/pwsz` actually points to the [`Setup-Profile.ps1`](base/Setup-Profile.ps1) script, which means, that after you have the `Scripts` directory setup, you can call `Setup-Profile` to update the `$PROFILE` after the `Setup-Profile.ps1` has been modified (or updated via `git pull`).


### The Short, but with control option
### The somewhat Short, but with control option
```PowerShell ```PowerShell
$sfw=1; iwr https://lksz.me/pwsz | iex; _setup [-sudo] [-Force] [-NoGitClone] [-GitURL <alternative git URL>] [-WhatIf] [-Confirm] [<CommonParameters>] $sfw=1; iwr https://lksz.me/pwsz | iex; _setup [-sudo] [-Force] [-NoGitClone] [-GitURL <alternative git URL>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```


The key here is `$sfw=1`, which can be substitued with the more verbose `$SetupFromWeb=1`, this let's the [`Setup-Profile`](Setup-Profile.ps1) script know to just load it's content, but allow you to manually call it's internal function via `_setup`
The key here is `$sfw=1`, which can be substitued with the more verbose `$SetupFromWeb=1`, this let's the [`Setup-Profile`](base/Setup-Profile.ps1) script know to just load it's content, but allow you to manually call it's internal function via `_setup`


### The 'I don't trust one liners, what's going on ?!?' option ### The 'I don't trust one liners, what's going on ?!?' option
You can always clone the git repo first, and only then run the [`Setup-Profile.ps1`](Setup-Profile.ps1) script.
You can always clone the git repo first, and only then run the [`Setup-Profile.ps1`](base/Setup-Profile.ps1) script.

+ 0
- 88
Reload-MyScripts.ps1 View File

@@ -1,88 +0,0 @@
[CmdletBinding(SupportsShouldProcess)]param()

try { Get-Alias Get-MyAliases -ErrorAction Stop | ForEach-Object { Remove-Item "Alias:$($_.Name)" } } catch {}
function Get-MyAliases {
[CmdletBinding(SupportsShouldProcess)]param([switch]$ScriptsOnly)

$local:allAliases = @()

$MyAliasScope = 0
$local:_scope = 0
$local:_done = $false
do {
try {
$local:newAliases += Get-Alias -Scope $_scope |
Where-Object {
($_.Definition -match "^$MyPSScriptRoot") -or (-not $ScriptsOnly -and ($_.Description -match '#MyAlias'))
}
if( $newAliases ) {
$allAliases += $newAliases
$MyAliasScope = $_scope;
Write-Verbose "`$MyAliasScope is now set to $MyAliasScope"
}
} catch {
Write-Verbose "catch: $($_.Exception.Message)"
$_done = $_.Exception.Message -match 'The scope .* exceeds'
}
$_scope += 1
} until ( $_done )

$allAliases
}

function getScriptName{param([string]$FullPath)
$FullPath -replace '\.ps1$','' -replace "^$([regex]::Escape($MyPSScriptRoot)).",''
}

$local:myAliases = [ordered]@{}
if( Test-Path $(Join-Path $MyPSScriptRoot Aliases) ) {
Get-ChildItem $(Join-Path $MyPSScriptRoot Aliases) | ForEach-Object {
$myAliases[$_.BaseName] = Get-Content $_.FullName
}
}

$local:IsVerbose = [bool]($PSBoundParameters['Verbose'])

$script:MyAliasScope = 0

$local:oldAliases = Get-MyAliases

$oldAliases = Get-Alias -Scope $MyAliasScope |
Where-Object Name -in $($oldAliases.Name + $myAliases.Keys)

if( $oldAliases -and $IsVerbose ) {
Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
}
if( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) {
$oldAliases | Remove-Alias -Scope $MyAliasScope
} else {
$oldAliases | ForEach-Object { Remove-Item "Alias:$($_.Name)" }
}

if( $(. Get-ScopeDepth) -gt 0 ) { Write-Host -ForegroundColor Red "Try sourcing Reload-MyScripts instead of just running it" }
Get-ChildItem $(Join-Path $MyPSScriptRoot profile.d) -Filter '*.ps1' | ForEach-Object {
Write-Verbose "Loading $(getScriptName $_.FullName)...";
". '$($_.FullName)';"
} | Invoke-Expression

$local:CommandsToAlias = (
@( $MyPSScriptRoot ) + $(
[SystemName]::_GetValidValues("",$true,$true) | ForEach-Object {
Join-Path $MyPSScriptRoot "sys.$_"
}
)) | ForEach-Object {
if( Test-Path $_ ) {
Get-ChildItem (Join-Path $_ '*.ps1') | Where-Object Name -notmatch '\.inc\.ps1$'
}
}

$CommandsToAlias | ForEach-Object {
Write-Verbose "Creating alias for $(getScriptName $_.FullName) Script..."
Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope
}

foreach( $local:alias in $myAliases.Keys ) {
Write-Verbose "Adding $($alias) alias..."
Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope
}


sys.Linux/Get-PlexInfo.ps1 → base.linux/Get-PlexInfo.ps1 View File


sys.Linux/Invoke-ViaAnsible.ps1 → base.linux/Invoke-ViaAnsible.ps1 View File


sys.Linux/Pull-ViaAnsible.ps1 → base.linux/Pull-ViaAnsible.ps1 View File


+ 6
- 0
base.linux/Set-EnvVariable.ps1 View File

@@ -0,0 +1,6 @@
[CmdletBinding()]param(
[string]$Name,
[object]$Value
)

Set-Item -Path (Join-Path "env:" $Name) -Value $Value

sys.Linux/Update-ArchOSz.ps1 → base.linux/Update-ArchOSz.ps1 View File


sys.Linux/Update-OSz.ps1 → base.linux/Update-OSz.ps1 View File


sys.Linux/Update-UbuntuOSz.ps1 → base.linux/Update-UbuntuOSz.ps1 View File


sys.Linux/Update-ViaAnsible.ps1 → base.linux/Update-ViaAnsible.ps1 View File


+ 16
- 0
base.linux/_.package.json View File

@@ -0,0 +1,16 @@
{
"package": {
"Condition": [
{
"custom": null,
"System": [
"Linux"
],
"Hostname": null,
"Username": null,
"Logic": 0
}
],
"Name": "base.linux"
}
}

sys.Linux/ls.ps1 → base.linux/ls.ps1 View File


sys.Linux/sranger.ps1 → base.linux/sranger.ps1 View File


sz-df.ps1 → base.linux/sz-df.ps1 View File


sz-du.ps1 → base.linux/sz-du.ps1 View File


sys.Linux/sz-rsync.ps1 → base.linux/sz-rsync.ps1 View File


sys.Linux/txm.ps1 → base.linux/txm.ps1 View File


+ 11
- 0
base.win/Set-EnvVariable.ps1 View File

@@ -0,0 +1,11 @@
[CmdletBinding()]param(
[string]$Name,
[object]$Value,
[ValidateSet('User','Machine')]
[string]$Persist
)

Set-Item -Path (Join-Path "env:" $Name) -Value $Value
if( $Persist ) {
[environment]::setEnvironmentVariable($Name, $Value, $Persist)
}

+ 16
- 0
base.win/_.package.json View File

@@ -0,0 +1,16 @@
{
"package": {
"Name": "base.win",
"Condition": [
{
"custom": null,
"System": [
"Windows"
],
"Hostname": null,
"Username": null,
"Logic": 0
}
]
}
}

+ 21
- 0
base/Add-PackageCondition.ps1 View File

@@ -0,0 +1,21 @@
[CmdletBinding(SupportsShouldProcess)]param(
[Parameter(mandatory=$true, ValueFromPipeline=$true)]
[szPackage]$InputObject,
[szLogic]$logic = "and",
[ScriptBlock]$CustomCondition,
[string[]]$System = $null,
[string[]]$Hostname = $null,
[string[]]$Username = $null
)

process {
$local:newCond = New-Object -Type 'szCondition'
$newCond.custom = $CustomCondition
$newCond.System = $System
$newCond.Hostname = $Hostname
$newCond.Username = $null
$newCond.Logic = [szLogic]::and
$InputObject.Condition += $newCond
$InputObject
}

Aliases/dcedit.ps1 → base/Aliases/dcedit.ps1 View File


Aliases/dco.ps1 → base/Aliases/dco.ps1 View File


Aliases/dps.ps1 → base/Aliases/dps.ps1 View File


Aliases/edit → base/Aliases/edit View File


Aliases/l.ps1 → base/Aliases/l.ps1 View File


Aliases/ll.ps1 → base/Aliases/ll.ps1 View File


Aliases/sz-update.ps1 → base/Aliases/sz-update.ps1 View File


Aliases/vi → base/Aliases/vi View File


Aliases/vidc.ps1 → base/Aliases/vidc.ps1 View File


Aliases/vim → base/Aliases/vim View File


ConvertFrom-Base64.ps1 → base/ConvertFrom-Base64.ps1 View File


Edit-MyConfig.ps1 → base/Edit-MyConfig.ps1 View File


Edit-MyProfiles.ps1 → base/Edit-MyProfiles.ps1 View File


Edit-MyScript.ps1 → base/Edit-MyScript.ps1 View File

@@ -16,10 +16,13 @@
$commandAst, $commandAst,
$fakeBoundParameters $fakeBoundParameters
) )
[SystemName]::_GetValidValues($wordToComplete,$false,$true)
$local:NotAll = $true
if( $fakeBoundParameters.ContainsKey("All") ) { $NotAll = -not $fakeBoundParameters.All }
[Packagesz]::_GetValidValues($wordToComplete,$NotAll,$true)
})] })]
[string]$System,
[string]$Package,
[switch]$ForceImport, [switch]$ForceImport,
[switch]$All,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({ param ( [ArgumentCompleter({ param (
$commandName, $commandName,
@@ -28,18 +31,25 @@
$commandAst, $commandAst,
$fakeBoundParameters $fakeBoundParameters
) )
$local:possibleValues = [MyScript]::_GetValidValues($wordToComplete,$true)
if( $fakeBoundParameters.ContainsKey("System") ) {
$possibleValues = $possibleValues | Where-Object { $_ -match "^sys\.$($fakeBoundParameters.System)" } | ForEach-Object { $_ -replace "^sys\.$($fakeBoundParameters.System).",'' }
$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,'') }
} }

$possibleValues $possibleValues
})] })]
[string[]]$ScriptName [string[]]$ScriptName
) )


$local:EditRootPath=$MyPSScriptRoot $local:EditRootPath=$MyPSScriptRoot
if( $System ) {
$EditRootPath = Join-Path $EditRootPath "sys.$System"
if( $Package ) {
$EditRootPath = Join-Path $EditRootPath $Package
} }
$local:ScriptPaths = @() $local:ScriptPaths = @()
foreach( $local:p in $ImportFunction ) { foreach( $local:p in $ImportFunction ) {

Edit-TextFile.ps1 → base/Edit-TextFile.ps1 View File


+ 21
- 0
base/Get-MyPackages.ps1 View File

@@ -0,0 +1,21 @@
[CmdletBinding()]param(
[Parameter(ParameterSetName="OptionA")]
[Parameter(ParameterSetName="Path")]
[switch]$Force,
[Parameter(ParameterSetName="Path",Mandatory)]
[switch]$ReturnFullPath,
[Parameter(ParameterSetName="Path")]
[switch]$IncludeRoot
)

$local:packages = [Packagesz]::_GetValidValues("", -not $Force, $true) | Sort-Object
if( $IncludeRoot -and $ReturnFullPath ) { $MyPSScriptRoot }
foreach ( $local:pkg in $packages ) {
if( $ReturnFullPath ) {
Join-Path $MyPSScriptRoot $pkg
} else {
$pkg
}
}



+ 44
- 0
base/Get-MyScript.ps1 View File

@@ -0,0 +1,44 @@
[CmdletBinding()]param(
[Parameter(ParameterSetName="Normal")]
[Parameter(ParameterSetName="DropNamespace")]
[string]$Filter,
[Parameter(ParameterSetName="ByPackage",Mandatory)]
[Parameter(ParameterSetName="DropNamespace",Mandatory)]
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
$local:NotAll = $true
if( $fakeBoundParameters.ContainsKey("Force") ) { $NotAll = -not $fakeBoundParameters.Force }
[Packagesz]::_GetValidValues($wordToComplete,$NotAll,$true)
})]
[string]$Package,
[Parameter(ParameterSetName="Normal")]
[Parameter(ParameterSetName="ByPackage")]
[Parameter(ParameterSetName="DropNamespace",Mandatory)]
[switch]$NamesOnly,
[Parameter(ParameterSetName="Normal")]
[Parameter(ParameterSetName="ByPackage")]
[Parameter(ParameterSetName="DropNamespace")]
[switch]$Force,
[Parameter(ParameterSetName="DropNamespace",Mandatory)]
[switch]$DropNamespace
)
$local:rVal = [MyScript]::_GetValidValues($Filter,-not $Force,$true)

if( $Package ) {
$Package = Join-Path $Package ''
$rVal = $rVal |
Where-Object { $_ -match "^$Package" }
if( $DropNamespace ) {
$rVal = $rVal |
ForEach-Object { $_.Replace($Package,'') }
}
}

if( $NamesOnly ) { return $rVal }
return $rVal | ForEach-Object { Join-Path $MyPSScriptRoot "$_`.ps1" }


Get-Path.ps1 → base/Get-Path.ps1 View File


Get-PossibleArguments.ps1 → base/Get-PossibleArguments.ps1 View File


Get-Profiles.ps1 → base/Get-Profiles.ps1 View File


Get-ScopeDepth.ps1 → base/Get-ScopeDepth.ps1 View File


Invoke-Sudo.ps1 → base/Invoke-Sudo.ps1 View File


+ 5
- 0
base/New-MyPackage.ps1 View File

@@ -0,0 +1,5 @@
[CmdletBinding(SupportsShouldProcess)]param(
[string]$Name
)

[szPackage]::Create($Name)

+ 111
- 0
base/Reload-MyScripts.ps1 View File

@@ -0,0 +1,111 @@
[CmdletBinding(SupportsShouldProcess)]param()

try { Get-Alias Get-MyAliases -ErrorAction Stop | ForEach-Object { Remove-Item "Alias:$($_.Name)" } } catch {}
function Get-MyAliases {
[CmdletBinding(SupportsShouldProcess)]param([switch]$ScriptsOnly)

$local:allAliases = @()

$MyAliasScope = 0
$local:_scope = 0
$local:_done = $false
do {
try {
$local:newAliases += Get-Alias -Scope $_scope |
Where-Object {
($_.Definition -match "^$MyPSScriptRoot") -or (-not $ScriptsOnly -and ($_.Description -match '#MyAlias'))
}
if( $newAliases ) {
$allAliases += $newAliases
$MyAliasScope = $_scope;
Write-Verbose "`$MyAliasScope is now set to $MyAliasScope"
}
} catch {
Write-Verbose "catch: $($_.Exception.Message)"
$_done = $_.Exception.Message -match 'The scope .* exceeds'
}
$_scope += 1
} until ( $_done )

$allAliases
}

function getScriptName{param([string]$FullPath)
$FullPath -replace '\.ps1$','' -replace "^$([regex]::Escape($MyPSScriptRoot)).",''
}

$local:IsVerbose = [bool]($PSBoundParameters['Verbose'])

# Loads mandatory Package code
try {
$null = [Packagesz]
} catch {
$local:PackagePath = $(Join-Path $MyPSScriptRoot 'base')
Join-Path $(Join-Path $PackagePath profile.d) 'classes.ps1' |
Where-Object { Test-Path $_ } | ForEach-Object { . $_ }
}
$local:myPackages = Get-MyPackages -ReturnFullPath -IncludeRoot | Get-Item

$local:myAliases = [ordered]@{}

$myPackages |
ForEach-Object { Join-Path $_.FullName Aliases } |
Where-Object { Test-Path $_ } |
Get-ChildItem | ForEach-Object {
$myAliases[$_.BaseName] = Get-Content $_.FullName
}

$script:MyAliasScope = 0

$local:oldAliases = Get-MyAliases

$oldAliases = Get-Alias -Scope $MyAliasScope |
Where-Object Name -in $($oldAliases.Name + $myAliases.Keys)

if( $oldAliases -and $IsVerbose ) {
Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
}
if( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) {
$oldAliases | Remove-Alias -Scope $MyAliasScope
} else {
$oldAliases | ForEach-Object { Remove-Item "Alias:$($_.Name)" }
}

if( $(. Get-ScopeDepth) -gt 0 ) {
Write-Host -ForegroundColor Red "Try sourcing Reload-MyScripts instead of just running it"
}

foreach( $local:PackagePath in $myPackages ) {
$local:PackageName = $PackagePath.Name

Join-Path $PackagePath 'profile.d' | Where-Object { Test-Path $_ } |
Get-ChildItem -Filter '*.ps1' |
ForEach-Object {
Write-Verbose "Loading $(getScriptName $_.FullName)...";
". '$($_.FullName)';"
} |
Invoke-Expression
$local:CommandsToAlias = (
@( $PackagePath ) + $(
[SystemName]::_GetValidValues("",$true,$true) |
ForEach-Object {
Join-Path $PackagePath "sys.$_"
}
)) |
Where-Object { Test-Path $_ } |
ForEach-Object {
Get-ChildItem (Join-Path $_ '*.ps1') | Where-Object Name -notmatch '\.inc\.ps1$'
}
$CommandsToAlias | ForEach-Object {
Write-Verbose "Creating alias for $(getScriptName $_.FullName) Script..."
Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope
}
}

foreach( $local:alias in $myAliases.Keys ) {
Write-Verbose "Adding $($alias) alias..."
Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope
}


+ 38
- 0
base/Set-MyPackage.ps1 View File

@@ -0,0 +1,38 @@
[CmdletBinding(SupportsShouldProcess)]param(
[Parameter(mandatory=$true, ValueFromPipeline=$true)]
[szPackage]$InputObject,
[switch]$Force,
[switch]$PassThru,
[switch]$DryRun
)

process {
$local:outObj = @{ package = @{ Name = $InputObject.Name; Condition = @() } }
foreach( $local:c in $InputObject.Condition ) {
$local:newC = [ordered]@{}
foreach( $local:p in $c.PSObject.Properties ) {
if( $p.TypeNameOfValue -match 'ScriptBlock' -and $p.Value ) {
$newC[$p.Name] = $p.Value.ToString().Trim()
} else {
$newC[$p.Name] = $p.Value
}
}
$outObj.package.Condition += $newC;
}
$local:jsonOut = $outObj | ConvertTo-Json -Depth 4

if( -not $DryRun ) {
$local:jsonPath = Join-Path $MyPSScriptRoot $_.name
if( -not (Test-Path $jsonPath) ) { $null = New-Item -Type Directory $jsonPath -Force:$Force }
$jsonPath = Join-Path $jsonPath '_.package.json'
if( $Force -or -not (Test-Path $jsonPath) ) {
$jsonOut | Out-File $jsonPath -Force:$Force
} elseif ( Test-Path $jsonPath ) {
throw 'Package already exists!'
}
}

if( $PassThru ) {
$jsonOut
}
}

Setup-Profile.ps1 → base/Setup-Profile.ps1 View File

@@ -371,9 +371,23 @@ param(


$local:src = "" $local:src = ""
foreach ( $local:func in $FunctionName ) { foreach ( $local:func in $FunctionName ) {
$local:funcDef = $null
foreach( $cmd in (Get-Command -All $func) ) {
if( $cmd.CommandType -in @('Function','Filter') ) {
$funcDef = $cmd.Definition
break
} elseif( -$funcDef -and ($cmd.CommandType -in @('Script','ExternalScript')) ) {
$funcDef = Get-Content $cmd.Definition
}
}
if( -not $funcDef ) {
default { throw "Don't know how to handle $func" }
}

if ( -not $NoHeader ) { $src += "`nfunction $func {" } if ( -not $NoHeader ) { $src += "`nfunction $func {" }
$src += "`n" $src += "`n"
$src += $((Get-Command -Type Function $func).Definition)
$src += $funcDef
if ( -not $NoHeader ) { $src += "`n}" } if ( -not $NoHeader ) { $src += "`n}" }
$src += "`n" $src += "`n"
} }
@@ -410,11 +424,12 @@ $local:My_PSScriptRoot = Join-Path (Split-Path -Parent $MyPSModulePath) Scripts
Write-Verbose "MyPSScriptRoot = $My_PSScriptRoot" Write-Verbose "MyPSScriptRoot = $My_PSScriptRoot"
if ( -not (Test-Path $My_PSScriptRoot) ) { if ( -not (Test-Path $My_PSScriptRoot) ) {
New-Item -ItemType Directory -Path $My_PSScriptRoot -Force | Out-Null New-Item -ItemType Directory -Path $My_PSScriptRoot -Force | Out-Null
New-Item -ItemType Directory -Path $My_PSScriptRoot/profile.d -Force | Out-Null
New-Item -ItemType Directory -Path $(Join-Path $My_PSScriptRoot base) -Force | Out-Null
New-Item -ItemType Directory -Path $(Join-Path $(Join-Path $My_PSScriptRoot base) profile.d) -Force | Out-Null
} }
$global:MyPSScriptRoot = $My_PSScriptRoot $global:MyPSScriptRoot = $My_PSScriptRoot


$p = @($p[0], $MyPSScriptRoot) + $($p | Select-Object -Skip 1)
$p = @($p[0], $(Join-Path $My_PSScriptRoot base)) + $($p | Select-Object -Skip 1)
$env:PATH = $p -join $PathEnvDelimiter $env:PATH = $p -join $PathEnvDelimiter
} }



Stop-ProcessTree.ps1 → base/Stop-ProcessTree.ps1 View File


+ 5
- 0
base/_.package.json View File

@@ -0,0 +1,5 @@
{
"package": {
"name": "base"
}
}

+ 32
- 0
base/profile.d/Docker.class.ps1 View 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)
}
}


profile.d/FromPowerShellCookbook.ps1 → base/profile.d/FromPowerShellCookbook.ps1 View File


profile.d/FunctionName.class.ps1 → base/profile.d/FunctionName.class.ps1 View File


profile.d/MyConfig.class.ps1 → base/profile.d/MyConfig.class.ps1 View File

@@ -1,9 +1,9 @@
class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator { class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
hidden static [hashtable]$_HardCodedConfigDict = @{ hidden static [hashtable]$_HardCodedConfigDict = @{
'myconfig' = @($(Join-Path $(Join-Path $MyPSScriptRoot 'src') 'config.files.json'),
$(Join-Path $(Join-Path $MyPSScriptRoot 'src') 'config.files.local.json'))
'mymodules' = @($(Join-Path $(Join-Path $MyPSScriptRoot 'src') 'modules.json'),
$(Join-Path $(Join-Path $MyPSScriptRoot 'src') 'modules.local.json'))
'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() { static [hashtable]GetConfigDictionary() {

+ 16
- 0
base/profile.d/MyScript.class.ps1 View 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)
}
}

profile.d/Style.ps1 → base/profile.d/Style.ps1 View File


profile.d/Test-MyModules.ps1 → base/profile.d/Test-MyModules.ps1 View File


profile.d/UnixCompleters.ps1 → base/profile.d/UnixCompleters.ps1 View File


+ 3
- 0
base/profile.d/classes.ps1 View 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')"


profile.d/env.local.ps1.template → base/profile.d/env.local.ps1.template View File


profile.d/env.ps1 → base/profile.d/env.ps1 View File


profile.d/load-z.ps1 → base/profile.d/load-z.ps1 View File


+ 97
- 0
base/src/Packagesz.class.inc.ps1 View File

@@ -0,0 +1,97 @@
class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
static [hashtable]GetPackageDictionary() {
$local:packages = @{}

Get-ChildItem $global:MyPSScriptRoot |
ForEach-Object { Join-Path $_.FullName "_.package.json" } |
Where-Object { Test-Path $_ } |
Get-Item |
ForEach-Object {
$local:testPkg = Get-Content $_ -Raw |
ConvertFrom-Json |
Select-Object -ExpandProperty "package" -ErrorAction SilentlyContinue
if( $testPkg ) {
$local:k = $_.Directory.FullName.Replace($MyPSScriptRoot,'') -replace '^/',''
$packages[$k] = $testPkg
}
}

return $packages;
}
static [bool] ValidatePackageConditions($Package) {
if( -not $Package.Condition ) { return $true }
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
$local:hostname = $(hostname)
$local:username = $env:USER ?? $env:USERNAME
foreach( $local:c in $Package.Condition ) {
if( $valid -eq ($c.Logic -in ([szLogic]::or, [szLogic]::ornot )) ) { continue }

$local:v = $true;
if( $v -and $c.System ) {
$v = $v -and $($c.System | Where-Object { $currentSys -contains $_ })
}
if( $v -and $c.Hostname ) {
$v = $v -and $($c.Hostname | Where-Object { $hostname -match $_ })
}
if( $v -and $c.Username ) {
$v = $v -and $($c.Username | Where-Object { $username -match $_ })
}
if( $v -and $c.custom ) {
$v = $v -and ([bool]$(Invoke-ScriptBlock ([ScriptBlock]::Create($c.custom))))
}
switch( $c.Logic ) {
[szLogic]::not { $valid = $valid -and -not $v }
[szLogic]::or { $valid = $valid -or $v }
[szLogic]::ornot { $valid = $valid -or -not $v }
default { $valid = $valid -and $v }
}
}
return $valid
}
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$CurrentOnly,[bool]$Strict) {
$local:pkgz = [Packagesz]::GetPackageDictionary()
$local:possibleValues = $pkgz.Keys |
Where-Object { -not $CurrentOnly -or $(
[Packagesz]::ValidatePackageConditions($pkgz[$_])
) }
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}

[String[]] GetValidValues() {
return [Packagesz]::_GetValidValues('',$false,$true)
}
}

enum szLogic {
and = 0
not = 1 # nand
or = 2
ornot = 3
}

class szCondition {
[ScriptBlock]$custom = { $true }
[string[]]$System = $null
[string[]]$Hostname = $null
[string[]]$Username = $null
[szLogic]$Logic = [szLogic]::and

[string] ToString() {
return "Logic = $($this.Logic); System = $($this.System); Hostname = $($this.Hostname); Username = $($this.Username); Custom = { $($this.Custom.ToString().Trim()) }"
}
}

class szPackage {
[string]$Name
[szCondition[]]$Condition

static [szPackage]Create($Name) {
$local:newPkg = New-Object -Type 'szPackage'
$newPkg.Name = $Name
$newPkg.Condition = @()

return $newPkg
}
}

profile.d/SystemName.class.ps1 → base/src/SystemName.class.inc.ps1 View File

@@ -18,6 +18,7 @@ class SystemName { #: System.Management.Automation.IValidateSetValuesGenerator {
} }
$possibleValues.out = $possibleValues.out | $possibleValues.out = $possibleValues.out |
Select-Object -Unique | Select-Object -Unique |
Where-Object { $_ } |
Sort-Object { Sort-Object {
$local:sortName = "zz_$_"; $local:sortName = "zz_$_";
if( $_ -in $possibleValues.Exist -and $_ -in $possibleValues.Current ) { $sortName[0] = "a" } if( $_ -in $possibleValues.Exist -and $_ -in $possibleValues.Current ) { $sortName[0] = "a" }

src/config.files.json → base/src/config.files.json View File

@@ -37,6 +37,8 @@
"ssh-pub": "~/.ssh/id_*.pub", "ssh-pub": "~/.ssh/id_*.pub",
"ssh-id": ["~/.ssh/id_ed25519","~/.ssh/id_rsa"], "ssh-id": ["~/.ssh/id_ed25519","~/.ssh/id_rsa"],
"ssh-auth": "~/.ssh/authorized_keys", "ssh-auth": "~/.ssh/authorized_keys",
"ssh-conf": "/etc/ssh/sshd_config",
"ssh" : [ "#ssh-auth", "#ssh-conf", "#ssh-pub", "#ssh-id" ]
"ssh-known": "~/.ssh/known_hosts",
"ssh-conf": "~/.ssh/config",
"sshd-conf": "/etc/ssh/sshd_config",
"ssh" : [ "#ssh-auth", "#ssh-known", "#ssh-conf", "#sshd-conf", "#ssh-pub", "#ssh-id" ]
} }

src/modules.json → base/src/modules.json View File


src/smartsudo.inc.ps1 → base/src/smartsudo.inc.ps1 View File


+ 0
- 3
dcc.ps1 View File

@@ -1,3 +0,0 @@
[CmdletBinding(SupportsShouldProcess)]param([string[]]$ProjectPath=@($PWD))

$ProjectPath | ForEach-Object { docker-compose --file $(Resolve-Path $(Join-Path $_ docker-compose.yml)) config | less }

+ 0
- 1
dcdown.ps1 View File

@@ -1 +0,0 @@
docker-compose down --timeout=3 --volumes --remove-orphans "$args"

+ 0
- 10
dcup.ps1 View File

@@ -1,10 +0,0 @@
#[CmdletBinding(SupportsShouldProcess)]param()

$local:dcParams = [string]::Empty
if( $args ) {
$dcParams = $args | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
}
docker-compose up -d --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams

Edit-DockerCompose.ps1 → docker/Edit-DockerCompose.ps1 View File

@@ -1,4 +1,18 @@
[CmdletBinding(SupportsShouldProcess)]param([string[]]$ProjectPath=@($PWD),[switch]$Force)
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[switch]$Force,
[string[]]$AdditionalFiles

)


$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml') $local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml')
$local:editFiles = @() $local:editFiles = @()
@@ -9,6 +23,6 @@ foreach( $local:fileName in $EditCandidates ) {
} }
} }


Edit-TextFile $editFiles
Edit-TextFile ($($editFiles | Sort-Object) + $AdditionalFiles)


$editFiles | Select-Object -First 1 | ForEach-Object { docker-compose --file $(Resolve-Path $_) config -q } $editFiles | Select-Object -First 1 | ForEach-Object { docker-compose --file $(Resolve-Path $_) config -q }

Get-DockerProcess.ps1 → docker/Get-DockerProcess.ps1 View File


+ 14
- 0
docker/_.package.json View File

@@ -0,0 +1,14 @@
{
"package": {
"Condition": [
{
"custom": "Get-Command docker -Type Application",
"System": null,
"Hostname": null,
"Username": null,
"Logic": 0
}
],
"Name": "docker"
}
}

+ 14
- 0
docker/dcc.ps1 View File

@@ -0,0 +1,14 @@
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD)
)

$ProjectPath | ForEach-Object { docker-compose --file $(Resolve-Path $(Join-Path $_ docker-compose.yml)) config | less }

+ 18
- 0
docker/dcdown.ps1 View File

@@ -0,0 +1,18 @@
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
)

$ProjectPath | ForEach-Object {
docker-compose --file $(Resolve-Path $(Join-Path $_ docker-compose.yml)) down --timeout=3 --volumes --remove-orphans "$CliParams"
}

dcl.ps1 → docker/dcl.ps1 View File


dcll.ps1 → docker/dcll.ps1 View File


dcr.ps1 → docker/dcr.ps1 View File


dcre.ps1 → docker/dcre.ps1 View File


dcreup.ps1 → docker/dcreup.ps1 View File


+ 28
- 0
docker/dcup.ps1 View File

@@ -0,0 +1,28 @@
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
)

$local:dcParams = [string]::Empty
if( $CliParams ) {
$dcParams = $CliParams | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
}
$ProjectPath | ForEach-Object {
$local:dcPath = $(Resolve-Path $(Join-Path $_ docker-compose.yml))
Write-Verbose "docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams"
docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams
}


dcx.ps1 → docker/dcx.ps1 View File


di.ps1 → docker/di.ps1 View File


dll.ps1 → docker/dll.ps1 View File


dl.ps1 → docker/dlogs.ps1 View File


dx.ps1 → docker/dx.ps1 View File


+ 0
- 15
profile.d/MyScript.class.ps1 View File

@@ -1,15 +0,0 @@
class MyScript { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $(
Get-ChildItem $global:MyPSScriptRoot -Filter '*.ps1' -Recurse |
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('',$true)
}
}

Loading…
Cancel
Save