-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall.ps1
More file actions
167 lines (133 loc) · 5.52 KB
/
Install.ps1
File metadata and controls
167 lines (133 loc) · 5.52 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# ==========================================================================
# Install Script - OMP, PS7, CaskaydiaCove Nerd Font, Theme Menu
# In VScode add 'CaskaydiaCove NF' to terminal.integrated.fontFamily manually
# also set terminal.integrated.minimumContrastRatio to 0
# ==========================================================================
# Ensure the script runs as Administrator
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
Write-Error "Please run this script as Administrator."
exit 1
}
$ErrorActionPreference = "Stop"
$installDir = "C:\ompinstall"
$fontsDir = "$installDir\Fonts"
$themesDir = "$installDir\themes"
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
New-Item -ItemType Directory -Force -Path $fontsDir | Out-Null
New-Item -ItemType Directory -Force -Path $themesDir | Out-Null
Write-Host ""
Write-Host "=== Starting installation ==="
Write-Host ""
# ------------------------------
# Install Oh My Posh
# ------------------------------
if (-not (Get-Command oh-my-posh -ErrorAction SilentlyContinue)) {
Write-Host "Installing Oh My Posh..."
winget install JanDeDobbeleer.OhMyPosh -e --accept-package-agreements --accept-source-agreements
} else {
Write-Host "Oh My Posh already installed."
}
# ------------------------------
# Install PowerShell 7
# ------------------------------
$isArm = $env:PROCESSOR_ARCHITECTURE -like "*ARM*"
if ($isArm) {
$arch = "arm64"
} else {
$arch = "x64"
}
$version = "7.5.4"
$pwshUrl = "https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-$arch.msi"
$pwshMsi = "$installDir\pwsh.msi"
if (-not (Get-Command pwsh.exe -ErrorAction SilentlyContinue)) {
Write-Host "Installing PowerShell 7 ($arch)..."
Invoke-WebRequest -Uri $pwshUrl -OutFile $pwshMsi
Start-Process msiexec.exe -ArgumentList "/i `"$pwshMsi`" /quiet /norestart" -Wait
} else {
Write-Host "PowerShell 7 already installed."
}
# ------------------------------
# Install Nerd Font
# ------------------------------
$fontZipUrl = "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/CascadiaCode.zip"
$fontZipPath = "$installDir\CascadiaCode.zip"
if (-not (Get-ChildItem $fontsDir -Filter *.ttf -ErrorAction SilentlyContinue)) {
Write-Host "Downloading Nerd Fonts..."
Invoke-WebRequest -Uri $fontZipUrl -OutFile $fontZipPath
Expand-Archive -Path $fontZipPath -DestinationPath $fontsDir -Force
}
Write-Host "Installing Fonts..."
$fontFiles = Get-ChildItem "$fontsDir\*Caskaydia*.ttf"
foreach ($font in $fontFiles) {
$dest = "$env:WINDIR\Fonts\$($font.Name)"
if (-not (Test-Path $dest)) {
Copy-Item $font.FullName $dest -Force
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -Name $font.Name -Value $font.Name -PropertyType String -Force | Out-Null
Write-Host "Installed font: $($font.Name)"
}
else {
Write-Host "Font already installed: $($font.Name)"
}
}
# ------------------------------
# Theme selection menu
# ------------------------------
$themes = Get-ChildItem "$themesDir\*.json"
if ($themes.Count -eq 0) {
Write-Host "No themes found in $themesDir"
exit 1
}
Write-Host ""
Write-Host "Available Themes:"
Write-Host ""
for ($i = 0; $i -lt $themes.Count; $i++) {
Write-Host "[$($i+1)] $($themes[$i].Name)"
}
$choice = Read-Host "Enter theme number"
$index = [int]$choice - 1
if ($index -lt 0 -or $index -ge $themes.Count) {
Write-Host "Invalid selection"
exit 1
}
$theme = $themes[$index]
Write-Host "Theme selected: $($theme.Name)"
# ------------------------------
# Configure PowerShell profiles
# ------------------------------
$OMPCommand = 'oh-my-posh init pwsh --config "' + $theme.FullName + '" | Invoke-Expression'
$PS7Profile = "$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
New-Item -ItemType File -Force -Path $PS7Profile | Out-Null
Set-Content $PS7Profile $OMPCommand
$PS5Profile = "$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
New-Item -ItemType File -Force -Path $PS5Profile | Out-Null
Set-Content $PS5Profile $OMPCommand
# ------------------------------
# Windows Terminal - set font per profile
# ------------------------------
$wtSettings = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
if (Test-Path $wtSettings) {
Write-Host "Updating all Windows Terminal profiles with correct font..."
$settingsJson = Get-Content $wtSettings -Raw | ConvertFrom-Json
if ($settingsJson.profiles.list) {
foreach ($profile in $settingsJson.profiles.list) {
if (-not $profile.font) {
$profile | Add-Member -NotePropertyName font -NotePropertyValue @{} -Force
}
$profile.font.face = "CaskaydiaCove NF"
}
$settingsJson | ConvertTo-Json -Depth 32 | Set-Content $wtSettings -Encoding UTF8
Write-Host "Windows Terminal profile fonts updated."
}
else {
Write-Host "No profiles found in Windows Terminal settings."
}
}
else {
Write-Host "Windows Terminal settings.json not found."
}
Write-Host ""
Write-Host "=== Installation complete ==="
Write-Host "Close and fully restart Windows Terminal."
Write-Host ""