-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
59 lines (50 loc) · 2.28 KB
/
Copy pathinstall.ps1
File metadata and controls
59 lines (50 loc) · 2.28 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
param(
[switch]$DryRun
)
if ($DryRun) {
Write-Host "=== DRY RUN MODE: No system configurations will be modified ===" -ForegroundColor Cyan
}
Write-Host "Starting Custom Scripts Installation for Windows..." -ForegroundColor Green
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$AliasesBat = Join-Path $ScriptDir "windows\aliases.bat"
$ProfilePs1 = Join-Path $ScriptDir "windows\profile.ps1"
Write-Host "1. Setting up Command Prompt aliases..." -ForegroundColor Yellow
if (-not $DryRun) {
try {
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Command Processor" -Name "AutoRun" -Value "`"$AliasesBat`"" -ErrorAction Stop
Write-Host "Successfully set Command Prompt AutoRun registry key." -ForegroundColor Green
} catch {
Write-Host "Failed to set registry key. You may need to run this script as Administrator." -ForegroundColor Red
}
} else {
Write-Host "[Dry Run] Would set registry key HKCU:\Software\Microsoft\Command Processor\AutoRun to `"$AliasesBat`"" -ForegroundColor Cyan
}
Write-Host "2. Setting up PowerShell profile..." -ForegroundColor Yellow
if (!(Test-Path -Path $PROFILE)) {
if (-not $DryRun) {
New-Item -Type File -Path $PROFILE -Force | Out-Null
Write-Host "Created new PowerShell profile."
} else {
Write-Host "[Dry Run] Would create new PowerShell profile at $PROFILE" -ForegroundColor Cyan
}
}
$ProfileContent = ""
if (Test-Path -Path $PROFILE) {
$ProfileContent = Get-Content -Path $PROFILE -Raw -ErrorAction Ignore
}
$SourcingCommand = ". `"$ProfilePs1`""
if ([string]::IsNullOrWhiteSpace($ProfileContent) -or $ProfileContent -notmatch [regex]::Escape($SourcingCommand)) {
if (-not $DryRun) {
Add-Content -Path $PROFILE -Value "`n# Load custom aliases`n$SourcingCommand"
Write-Host "Successfully injected profile source command into $PROFILE." -ForegroundColor Green
} else {
Write-Host "[Dry Run] Would inject profile source command into $PROFILE" -ForegroundColor Cyan
}
} else {
Write-Host "Profile source command already exists. Skipping." -ForegroundColor Green
}
if (-not $DryRun) {
Write-Host "Installation complete! Please restart your terminal." -ForegroundColor Green
} else {
Write-Host "Dry-run complete!" -ForegroundColor Green
}