diff --git a/base/Set-MyPackage.ps1 b/base/Set-MyPackage.ps1 index 61ef530..a8a165d 100644 --- a/base/Set-MyPackage.ps1 +++ b/base/Set-MyPackage.ps1 @@ -7,7 +7,9 @@ [switch]$LocalUser, [switch]$Force, [switch]$PassThru, - [switch]$DryRun + [switch]$DryRun, + [ValidateSet("Default","None")] + [string]$Template="Default" ) process { @@ -33,11 +35,23 @@ process { $outObj.package.Condition += $newC; } $local:jsonOut = $outObj | ConvertTo-Json -Depth 4 - + if( -not $DryRun ) { $local:pkgPath = Join-Path $MyPSScriptRoot $iObj.name Write-Verbose "pkgPath=$pkgPath" - if( -not (Test-Path $pkgPath) ) { $null = New-Item -Type Directory $pkgPath -Force:$Force } + if( -not (Test-Path $pkgPath) ) { + $null = New-Item -Type Directory $pkgPath -Force:$Force + } elseif ( -not $Force ) { + $Template = "None" + } + switch($Template){ + "Default" { + New-Item -Type Directory (Join-Path $pkgPath 'profile.d') + New-Item -Type Directory (Join-Path $pkgPath 'Aliases') + New-Item -Type Directory (Join-Path $pkgPath 'src') + New-Item -Type File -Path (Join-Path (Join-Path $pkgPath 'profile.d') 'env.local.ps1') -Value '' + } + } $jsonPath = Join-Path $pkgPath '_.package.json' if( $Force -or -not (Test-Path $jsonPath) ) { $jsonOut | Out-File $jsonPath -Force:$Force diff --git a/base/src/Packagesz.class.inc.ps1 b/base/src/Packagesz.class.inc.ps1 index 55bf7e2..b50da69 100644 --- a/base/src/Packagesz.class.inc.ps1 +++ b/base/src/Packagesz.class.inc.ps1 @@ -23,7 +23,9 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator { $local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot) $local:currentSys = [SystemName]::_GetValidValues('',$true,$true); $local:hostname = $(hostname) - $local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME }) + + $local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } ) + foreach( $local:c in $Package.Condition ) { if( $valid -eq ($c.Logic -in ([szLogic]::or, [szLogic]::ornot )) ) { continue } diff --git a/scoop/_.package.json b/scoop/_.package.json new file mode 100644 index 0000000..8c4ee64 Binary files /dev/null and b/scoop/_.package.json differ diff --git a/scoop/profile.d/smart-refresh-on-startup.ps1 b/scoop/profile.d/smart-refresh-on-startup.ps1 new file mode 100644 index 0000000..4182e97 --- /dev/null +++ b/scoop/profile.d/smart-refresh-on-startup.ps1 @@ -0,0 +1,20 @@ +$local:whenLast = $null +$local:whenLastSavePath = $(Join-Path $env:SCOOP last-scoop-refresh.clixml) + +if( Test-Path $whenLastSavePath ) { + $whenLast = Import-Clixml -LiteralPath $whenLastSavePath +} + +if( $whenLast ) { + $local:TimePassed = (Get-Date) - $local:whenLast + if( $TimePassed.TotalHours -ge 3 ) { + $whenLast = $null + } else { + Write-Host -ForegroundColor Yellow "Only $(ConvertFrom-TimeSpan $TimePassed) has passed, skipping scoop refresh." + } +} + +if( -not $whenLast ) { + scoop refresh + $whenLast | Export-Clixml -LiteralPath $whenLastSavePath +} \ No newline at end of file