From 386f3d77d45cb0ef79b043f4aef87ee095354f1a Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Fri, 25 Apr 2025 23:52:08 -0400 Subject: [PATCH] Introducing Windows --- .../{run_init.sh.tmpl => run_init.ps1.tmpl} | 36 +++++++++++++++++++ .../__root_links/base.chezmoiroot.windows | 1 + 2 files changed, 37 insertions(+) rename .chezmoiscripts/{run_init.sh.tmpl => run_init.ps1.tmpl} (59%) mode change 100755 => 100644 create mode 100644 chezmoi.roots/__root_links/base.chezmoiroot.windows diff --git a/.chezmoiscripts/run_init.sh.tmpl b/.chezmoiscripts/run_init.ps1.tmpl old mode 100755 new mode 100644 similarity index 59% rename from .chezmoiscripts/run_init.sh.tmpl rename to .chezmoiscripts/run_init.ps1.tmpl index 882467c..3bfb5b2 --- a/.chezmoiscripts/run_init.sh.tmpl +++ b/.chezmoiscripts/run_init.ps1.tmpl @@ -1,3 +1,4 @@ +{{- if ne .chezmoi.os "windows" -}} #! /usr/bin/env bash set -e @@ -56,3 +57,38 @@ exec sh -c 'rm ~/.config/chezmoi/chezmoistate.boltdb \ && chezmoi init && chezmoi apply \ && printf "apply with externals #1/2...\n" && CZ_EXTR=1 chezmoi apply \ && printf "apply with externals #2/2...\n" && CZ_EXTR=1 chezmoi apply' +{{- else -}} +#! /usr/bin/env pwsh +$local:CZROOTLINK=Join-Path "chezmoi.roots" (Join-Path "__root_links" "base.chezmoiroot") + +# Get-ChildItem -LiteralPath "env:" | Where-Object Name -imatch 'cz|chezmoi' +$local:CZ_SYS=$env:CZ_SYS +$local:CZ_CHASSIS=$env:CZ_CHASSIS +$local:CZ_ROOT_LINK=(Join-Path $env:CHEZMOI_SOURCE_DIR "$CZROOTLINK") + +Write-Host -ForegroundColor Green "System detected as $($env:CHEZMOI_OS)/$($env:CHEZMOI_ARCH), setting up .chezmoiroot and initializing..." + +if (Test-Path -PathType Leaf "$CZ_ROOT_LINK.$CZ_SYS.$CZ_CHASSIS") { + $CZ_ROOT_LINK = "$CZ_ROOT_LINK.$CZ_SYS.$CZ_CHASSIS" +} elseif(Test-Path -PathType Leaf "$CZ_ROOT_LINK.$CZ_SYS") { + $CZ_ROOT_LINK = "$CZ_ROOT_LINK.$CZ_SYS" +} elseif(Test-Path -PathType Leaf "$CZ_ROOT_LINK.$CZ_CHASSIS") { + $CZ_ROOT_LINK = "$CZ_ROOT_LINK.$CZ_CHASSIS" +} else { + Write-Host -ForegroundColor Red "Failed to find a matching .chezmoiroot. Aborting!" + exit 1 +} + +$local:newItem = [ordered]@{ + Type = "File" + Path = $env:CHEZMOI_SOURCE_DIR + + Name = ".chezmoiroot" + Value = @((Get-Content -LiteralPath $CZ_ROOT_LINK).Replace('\', '/')) -join "`n" +} +$null = New-Item @newItem -ErrorAction Stop + +Write-Host -ForegroundColor Green ".chezmoiroot initialized. You will need to run chezmoi init --apply again (the command is already in your clipboard)." +"chezmoi init --apply" | Set-Clipboard + +{{ end }} \ No newline at end of file diff --git a/chezmoi.roots/__root_links/base.chezmoiroot.windows b/chezmoi.roots/__root_links/base.chezmoiroot.windows new file mode 100644 index 0000000..4e2346c --- /dev/null +++ b/chezmoi.roots/__root_links/base.chezmoiroot.windows @@ -0,0 +1 @@ +_home.windows \ No newline at end of file