System specific update

Reload-Scripts now loads Platform/OS specific scripts depending on
current state.
This required the SystemName class

sranger is an example of running ranger as sudo, but only in Linux.

Moved Get-MyAliases into Reload-MyScripts, and changed Reload-MyScripts
to load Aliases dynamically via the Aliases directory.
This commit is contained in:
lksz 2020-10-02 12:45:04 -04:00
parent 45b53dc110
commit 2d2a7bba5d
8 changed files with 150 additions and 43 deletions

View file

@ -9,6 +9,16 @@
[FunctionName]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ImportFunction,
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[SystemName]::_GetValidValues($wordToComplete,$false,$true)
})]
[string]$System,
[switch]$ForceImport,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[ArgumentCompleter({ param (
@ -18,16 +28,24 @@
$commandAst,
$fakeBoundParameters
)
[MyScript]::_GetValidValues($wordToComplete,$true)
$local:possibleValues = [MyScript]::_GetValidValues($wordToComplete,$true)
if( $fakeBoundParameters.ContainsKey("System") ) {
$possibleValues = $possibleValues | Where-Object { $_ -match "^sys\.$($fakeBoundParameters.System)" } | ForEach-Object { $_ -replace "^sys\.$($fakeBoundParameters.System).",'' }
}
$possibleValues
})]
[string[]]$ScriptName
)
$local:EditRootPath=$MyPSScriptRoot
if( $System ) {
$EditRootPath = Join-Path $EditRootPath "sys.$System"
}
$local:ScriptPaths = @()
foreach( $local:p in $ImportFunction ) {
$local:f = Get-Command $p -Type Function
if( $f ) {
$local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
$local:sp = Join-Path $EditRootPath "$p`.ps1"
if( $ForceImport -or -not (Test-Path $sp) ) {
Export-FunctionSource $p -NoHeader > $sp
} elseif ( -not $ForceImport ) {
@ -37,12 +55,19 @@ foreach( $local:p in $ImportFunction ) {
}
}
foreach( $local:p in $ScriptName ) {
$local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
$local:sp = Join-Path $EditRootPath "$p`.ps1"
$ScriptPaths += $sp
}
if( -not $ScriptPaths ) {
$ScriptPaths += $MyPSScriptRoot
$ScriptPaths += $EditRootPath
}
foreach( $local:p in $ScriptPaths ) {
$local:parentPath = Split-Path -Parent $p;
if( -not (Test-Path $p) -and -not (Test-Path $parentPath) ) {
New-Item -Directory $parentPath
}
}
Edit-TextFile $ScriptPaths