Created
September 18, 2025 22:22
-
-
Save jc00ke/9cc51ae6e4efa6dab729420c4708129b to your computer and use it in GitHub Desktop.
PowerShell script to pull fresh dotfiles and then sync them to the right place on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define source and destination paths | |
| $DotFilesPath = "$HOME\dotfiles" | |
| Set-Location -Path $DotFilesPath | |
| git pull | |
| function SyncMyFiles { | |
| param( | |
| [string]$SourcePath, | |
| [string]$DestinationPath | |
| ) | |
| # 1. Delete files and directories in Destination that are NOT in Source | |
| # Get all items (files and directories) in the Destination recursively | |
| $DestinationItems = Get-ChildItem -Path $DestinationPath -Recurse -Force | |
| foreach ($Item in $DestinationItems) { | |
| # Construct the corresponding path in the source | |
| $SourceEquivalentPath = $Item.FullName.Replace($DestinationPath, $SourcePath) | |
| # Check if the item exists in the Source | |
| if (-not (Test-Path -Path $SourceEquivalentPath -PathType Any)) { | |
| Write-Host "Deleting $($Item.FullName) as it's not in the source." | |
| Remove-Item -Path $Item.FullName -Recurse -Force | |
| } | |
| } | |
| # 2. Copy files from Source to Destination, overwriting existing ones | |
| # Ensure the destination directory exists (Copy-Item -Recurse will create subfolders) | |
| New-Item -ItemType Directory -Path $DestinationPath -ErrorAction SilentlyContinue | |
| # Copy all files and folders from source to destination recursively | |
| Copy-Item -Path "$SourcePath\*" -Destination "$DestinationPath\" -Recurse -Force | |
| } | |
| SyncMyFiles -SourcePath "$DotFilesPath\.config\nvim" -DestinationPath "$env:LOCALAPPDATA\nvim" | |
| SyncMyFiles -SourcePath "$DotFilesPath\.config\mise" -DestinationPath "$HOME\.config\mise" | |
| Set-Location -Path $HOME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment