From c5311de65aa4535876ef8fbf8487fe801e9c3d36 Mon Sep 17 00:00:00 2001 From: "GalSz (Varnois VDI)" Date: Mon, 13 Dec 2021 23:23:45 -0500 Subject: [PATCH] Minor tweaks for windows env --- Setup-ScriptEnv.ps1 | 2 +- base/Get-MyModules.ps1 | 18 ++++++++++++++---- scoop/profile.d/smart-refresh-on-startup.ps1 | 11 +++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Setup-ScriptEnv.ps1 b/Setup-ScriptEnv.ps1 index c6fd034..8b9ef92 100644 --- a/Setup-ScriptEnv.ps1 +++ b/Setup-ScriptEnv.ps1 @@ -452,7 +452,7 @@ function _Init { } $_profiles | Foreach-Object { - $local:p = Invoke-Expression "`$profile.$_" + $local:p = $profile."$_" if( -not $p ) { $p = $_ } $local:profileContent = $randomSeed; $local:exists = Test-Path $p diff --git a/base/Get-MyModules.ps1 b/base/Get-MyModules.ps1 index 569fec5..65658c6 100644 --- a/base/Get-MyModules.ps1 +++ b/base/Get-MyModules.ps1 @@ -1,5 +1,12 @@ -param([switch]$IgnoreSystem,[switch]$MissingOnly,[switch]$GenInstallCode) +param( + [switch]$IgnoreSystem, + [switch]$MissingOnly, + [switch]$GenInstallCode, + [switch]$UserScope +) +$local:scopeStr = "" +if( $UserScope ) { $scopeStr = " -Scope CurrentUser" } $local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true)); $local:oldPSGet = Get-Module PowerShellGet -ListAvailable -ErrorAction SilentlyContinue | @@ -11,9 +18,9 @@ if( $local:oldPSGet ) { "PowerShellGet is an old version ($($oldPSGet.Version)), the following code should upgrade it" , "# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted" , " [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" - , " Install-PackageProvider -Name NuGet -Force" + , " Install-PackageProvider -Name NuGet -Force${scopeStr}" , " Remove-Module PowerShellGet" - , " Install-Module -Name PowerShellGet -Force" + , " Install-Module -Name PowerShellGet -Force${scopeStr}" , " Update-Module -Name PowerShellGet" ) -join "`n" ) } @@ -41,5 +48,8 @@ if( $GenInstallCode ) { } | ForEach-Object { if( -not $GenInstallCode ) { return $_ } "Write-Host -ForegroundColor Cyan 'Installing $_...';" - "Install-Module $_ -AllowClobber" + "Install-Module $_ -AllowClobber${scopeStr}" } +if( $GenInstallCode ) { + ". Reload-MyScripts" +} diff --git a/scoop/profile.d/smart-refresh-on-startup.ps1 b/scoop/profile.d/smart-refresh-on-startup.ps1 index 845e2d0..7e5b20c 100644 --- a/scoop/profile.d/smart-refresh-on-startup.ps1 +++ b/scoop/profile.d/smart-refresh-on-startup.ps1 @@ -6,14 +6,9 @@ if( -not (Test-Path variable:global:ScoopRefreshed) ) { $global:ScoopRefreshed = [SessionData]::Get("ScoopRefreshed",$false) if( -not $ScoopRefreshed ) { - if( Test-Path (Join-Path $env:SCOOP last-scoop-refresh.clixml) ) { - if($Host.Name -ne 'Visual Studio Code Host' ) { - scoop refresh - [SessionData]::Set("ScoopRefreshed",$true) - } - } else { - Write-Warning ("No recorded time for last 'scoop refresh', to remedy, run 'scoop refresh' at least once manually." + - "`nIf the issue still persists, please run 'scoop alias-update' to update to latest refresh code, and try again.") + if($Host.Name -ne 'Visual Studio Code Host' ) { + scoop refresh + [SessionData]::Set("ScoopRefreshed",$true) } }