Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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 {
Expand Down Expand Up @@ -110,4 +109,3 @@ function Disable-SurfaceLaptopPowerButton {
if (-not $SkipApply) {
Disable-SurfaceLaptopPowerButton | Out-Null
}
# {{ end }}
20 changes: 12 additions & 8 deletions tests/powershell/SurfaceLaptopPowerButton.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand All @@ -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"
Expand Down