diff --git a/README.md b/README.md index d11c7f9f..f6578a5e 100644 --- a/README.md +++ b/README.md @@ -372,9 +372,8 @@ The repository supports two installation modes: - **Light mode** (servers, CI, codespaces): Essential tools only - **Full mode** (dev servers, workstations): Full development tooling including Task and mise -On Windows, full mode also applies opinionated workstation settings. On -Microsoft Surface Laptop models, the hardware power button is set to **Do -nothing** for both AC and battery power. +On Windows, Microsoft Surface Laptop models always have the hardware power +button set to **Do nothing** for both AC and battery power. The mode is auto-detected based on: - Hostname patterns (SVLDEV* = full, SVL* = light) diff --git a/docs/customization.md b/docs/customization.md index 93756a53..1663c239 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -21,10 +21,9 @@ The repository supports two installation modes: - **Full mode** (dev servers, workstations) — Full development tooling including Task and mise. -On Windows, full mode also applies opinionated workstation settings. Microsoft -Surface Laptop models have the hardware power button set to **Do nothing** for -both AC and battery power, preventing an accidental press next to Delete from -suspending or shutting down the computer. +On Windows, Microsoft Surface Laptop models always have the hardware power +button set to **Do nothing** for both AC and battery power, preventing an +accidental press next to Delete from suspending or shutting down the computer. The mode is auto-detected based on: diff --git a/home/.chezmoiscripts/windows/run_onchange_disable-surface-laptop-power-button.ps1.tmpl b/home/.chezmoiscripts/windows/run_onchange_disable-surface-laptop-power-button.ps1 similarity index 94% rename from home/.chezmoiscripts/windows/run_onchange_disable-surface-laptop-power-button.ps1.tmpl rename to home/.chezmoiscripts/windows/run_onchange_disable-surface-laptop-power-button.ps1 index 4e0a7894..262f517d 100644 --- a/home/.chezmoiscripts/windows/run_onchange_disable-surface-laptop-power-button.ps1.tmpl +++ b/home/.chezmoiscripts/windows/run_onchange_disable-surface-laptop-power-button.ps1 @@ -1,7 +1,6 @@ -# {{ if and (eq .chezmoi.os "windows") (eq .installType "full") }} #!/usr/bin/env pwsh # Disable the hardware power button on Microsoft Surface Laptop models. -# Runs in the opinionated full profile and is idempotent. +# Runs on Windows and is idempotent. [Diagnostics.CodeAnalysis.SuppressMessageAttribute( "PSAvoidUsingWriteHost", @@ -28,7 +27,7 @@ function Test-SurfaceLaptop { $model = [string]$ComputerSystem.Model return $manufacturer.Trim() -eq "Microsoft Corporation" -and - $model.Trim() -match "^Surface Laptop(?:\s|$)" + $model.Trim() -match "^(?:Microsoft )?Surface Laptop(?:[\s,]|$)" } function Invoke-PowerCfg { @@ -110,4 +109,3 @@ function Disable-SurfaceLaptopPowerButton { if (-not $SkipApply) { Disable-SurfaceLaptopPowerButton | Out-Null } -# {{ end }} diff --git a/tests/powershell/SurfaceLaptopPowerButton.Tests.ps1 b/tests/powershell/SurfaceLaptopPowerButton.Tests.ps1 index 80073dc3..6cad04d8 100644 --- a/tests/powershell/SurfaceLaptopPowerButton.Tests.ps1 +++ b/tests/powershell/SurfaceLaptopPowerButton.Tests.ps1 @@ -7,10 +7,9 @@ BeforeAll { $script:RepoRoot = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent $script:ScriptPath = Join-Path $script:RepoRoot ` - "home\.chezmoiscripts\windows\run_onchange_disable-surface-laptop-power-button.ps1.tmpl" + "home\.chezmoiscripts\windows\run_onchange_disable-surface-laptop-power-button.ps1" - $scriptContent = Get-Content -LiteralPath $script:ScriptPath -Raw - . ([scriptblock]::Create($scriptContent)) -SkipApply + . $script:ScriptPath -SkipApply } Describe "Surface Laptop power button script" -Tag "Unit" { @@ -27,11 +26,9 @@ Describe "Surface Laptop power button script" -Tag "Unit" { $errors | Should -BeNullOrEmpty } - It "is limited to the Windows full profile" { - $content = Get-Content -LiteralPath $script:ScriptPath -Raw - - $content | Should -Match 'eq \.chezmoi\.os "windows"' - $content | Should -Match 'eq \.installType "full"' + It "is a non-template Windows script" { + $script:ScriptPath | Should -Match '\.ps1$' + $script:ScriptPath | Should -Not -Match '\.tmpl$' } It "recognizes Microsoft Surface Laptop models" { @@ -41,6 +38,13 @@ Describe "Surface Laptop power button script" -Tag "Unit" { }) | Should -BeTrue } + It "recognizes the Surface Laptop 7 SMBIOS model" { + Test-SurfaceLaptop -ComputerSystem ([pscustomobject]@{ + Manufacturer = "Microsoft Corporation" + Model = "Microsoft Surface Laptop, 7th Edition" + }) | Should -BeTrue + } + It "recognizes Surface Laptop Studio models" { Test-SurfaceLaptop -ComputerSystem ([pscustomobject]@{ Manufacturer = "Microsoft Corporation"