generated from spenserblack/dotfiles-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.ps1
48 lines (40 loc) · 1.36 KB
/
bootstrap.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<#
.SYNOPSIS
Copy registered files to the home directory.
.DESCRIPTION
Copy registered files to the home directory.
#>
$Dotfiles = $PSScriptRoot
$Destination = $HOME
function Bootstrap {
param (
[Parameter(Mandatory = $true)]
[string]$Registered
)
Get-ChildItem -Path $Registered -File -Recurse | ForEach-Object {
$Path = $_.FullName
$RelativePath = $Path -replace [regex]::Escape("$Registered\"), ""
$DestinationPath = "$Destination\$RelativePath"
if ($_.Name -eq ".gitkeep") {
return
}
# If the file already exists in the home directory, skip it.
if (Test-Path -Path $DestinationPath) {
Write-Error "Already exists: $DestinationPath"
return
}
# If the file to copy does not exist, throw an error.
if (-not (Test-Path -Path $Path)) {
throw "File not found: $Path"
}
$Directory = Split-Path -Path $DestinationPath
if (-not (Test-Path -Path $Directory)) {
New-Item -Path $Directory -ItemType Directory
}
Copy-Item -Path $Path -Destination $DestinationPath
Write-Output "Copied: $RelativePath"
}
}
Bootstrap -Registered "$Dotfiles\.all"
Bootstrap -Registered "$Dotfiles\.windows"
Write-Output "Bootstrap complete."