-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-Profile.ps1
More file actions
40 lines (33 loc) · 1.47 KB
/
Install-Profile.ps1
File metadata and controls
40 lines (33 loc) · 1.47 KB
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
# Install-Profile.ps1
# Safe installer: dot-sources repo Profile.ps1 from the user's $PROFILE
$repoProfile = Join-Path $PSScriptRoot "Profile.ps1"
if (-not (Test-Path $repoProfile)) {
Write-Error "Profile.ps1 not found at $repoProfile"
return
}
$profilePath = $PROFILE.CurrentUserAllHosts
if (-not $profilePath) { $profilePath = $PROFILE }
$profileDir = Split-Path $profilePath -Parent
if (-not (Test-Path $profileDir)) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
}
if (-not (Test-Path $profilePath)) {
New-Item -ItemType File -Path $profilePath -Force | Out-Null
}
$line = ". `"$repoProfile`""
$contents = Get-Content -Path $profilePath -ErrorAction SilentlyContinue
if ($contents -notcontains $line) {
Add-Content -Path $profilePath -Value $line
Write-Host "Added dot-source line to $profilePath" -ForegroundColor Green
} else {
Write-Host "Dot-source line already present in $profilePath" -ForegroundColor Yellow
}
$legacyProfile = Join-Path $profileDir "profile.ps1"
if (Test-Path $legacyProfile) {
$legacyContent = Get-Content -Path $legacyProfile -ErrorAction SilentlyContinue
if ($legacyContent -match '\\$Name:') {
Write-Warning "Found legacy profile.ps1 referencing '$$Name:'. This can cause ParserError. Consider removing or updating that file: $legacyProfile"
} else {
Write-Warning "A legacy profile.ps1 exists: $legacyProfile. Ensure your $PROFILE is dot-sourcing the repo Profile.ps1 instead."
}
}