From 1672c384ad5c9df8930d9b6911e660a4b92458d2 Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Sun, 7 Feb 2021 13:32:23 -0500 Subject: [PATCH] Package creation template and scoop package Set-MyPackage has a template option that will create skelaton content when a new package is created. Add scoop package, so that refresh will occur automatically on powershell launch if it hasn't been run in the past 3 hours. --- base/Set-MyPackage.ps1 | 20 ++++++++++++++++--- base/src/Packagesz.class.inc.ps1 | 4 +++- scoop/_.package.json | Bin 0 -> 1238 bytes scoop/profile.d/smart-refresh-on-startup.ps1 | 20 +++++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 scoop/_.package.json create mode 100644 scoop/profile.d/smart-refresh-on-startup.ps1 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 0000000000000000000000000000000000000000..8c4ee64f0c872896791335ed598c20ca6cf7d955 GIT binary patch literal 1238 zcmc(e%}c{T5XIkF@PAl_9u!*e+^dK^h%FTHP%Fe3T0fGOnu?*{Z}rlf%e14SA3 zb9Ua_H?#Zo`KEpC$^DpVu1K*S=qE~K>ITo|sp9mu(R5CHT8cM4fjYzHV750nx1kjK zreoqV-Re#`&CiQ_jT#{ph;?H#rFBSEpOJwjdB{u|`nA1B| zxYU%B3tC5g-RPcKOr+Bg#3i1X9f#Lr5f>>NEAoo3BS!d98oJeF3wt e=6`UXp?ktlir263Xy^avV`qrtUm>mdR{b}twstcB literal 0 HcmV?d00001 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