-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinstall.ps1
More file actions
executable file
·248 lines (211 loc) · 8.4 KB
/
install.ps1
File metadata and controls
executable file
·248 lines (211 loc) · 8.4 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env pwsh
# PowerShell Nerd Fonts Installer
# Select and install Nerd Fonts from https://www.nerdfonts.com/font-downloads
# Windows compatible version of install.sh
# Enable strict mode for better error handling
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# Function to write colored output
function Write-ColorOutput {
param(
[string]$Message,
[string]$ForegroundColor = "White"
)
Write-Host $Message -ForegroundColor $ForegroundColor
}
# Function to write error messages
function Write-ErrorMessage {
param([string]$Message)
Write-ColorOutput "ERROR: $Message" "Red"
}
# Function to write success messages
function Write-SuccessMessage {
param([string]$Message)
Write-ColorOutput "SUCCESS: $Message" "Green"
}
# Function to write info messages
function Write-InfoMessage {
param([string]$Message)
Write-ColorOutput "INFO: $Message" "Cyan"
}
# Function to clean up temporary files
function Remove-TempFiles {
param([string]$TempDir)
try {
if (Test-Path $TempDir) {
Remove-Item -Path $TempDir -Recurse -Force
Write-InfoMessage "Cleaned up temporary files"
}
}
catch {
Write-Host "Warning: Could not clean up temporary files: $_" -ForegroundColor Yellow
}
}
# Function to register fonts with Windows (best effort)
function Register-WindowsFonts {
param([string]$FontsPath)
try {
# Get all font files (.ttf and .otf)
$FontFiles = Get-ChildItem -Path $FontsPath -Include "*.ttf", "*.otf" -Recurse
if ($FontFiles.Count -eq 0) {
Write-Host "Warning: No font files found to register" -ForegroundColor Yellow
return
}
Write-InfoMessage "Attempting to register $($FontFiles.Count) font file(s) with Windows..."
# Try to use Windows Shell COM object to install fonts
$Shell = New-Object -ComObject Shell.Application
$FontsFolder = $Shell.Namespace(0x14) # Fonts folder
foreach ($FontFile in $FontFiles) {
try {
$FontsFolder.CopyHere($FontFile.FullName, 0x10) # 0x10 = overwrite existing
}
catch {
# Silent fail for individual font registration
}
}
Write-SuccessMessage "Font registration completed"
}
catch {
Write-Host "Warning: Could not register fonts with Windows system: $_" -ForegroundColor Yellow
Write-InfoMessage "Fonts are still installed in user directory and should work in most applications"
}
}
# Main script starts here
try {
Write-ColorOutput "[-] Download The Nerd fonts [-]" "Magenta"
Write-ColorOutput "#######################" "Magenta"
Write-ColorOutput "Select Nerd Font" "Yellow"
# Font list - exact same as bash script
$FontsList = @(
"Agave", "AnonymousPro", "Arimo", "AurulentSansMono", "BigBlueTerminal",
"0xProto", "3270", "AdwaitaMono", "Agave", "AnonymousPro", "Arimo", "AtkinsonHyperlegibleMono",
"AurulentSansMono", "BigBlueTerminal", "BitstreamVeraSansMono", "CascadiaCode",
"CascadiaMono", "CodeNewRoman", "ComicShannsMono", "CommitMono", "Cousine",
"D2Coding", "DaddyTimeMono", "DejaVuSansMono", "DepartureMono", "DroidSansMono",
"EnvyCodeR", "FantasqueSansMono", "FiraCode", "FiraMono", "GeistMono", "Go-Mono",
"Gohu", "Hack", "Hasklig", "HeavyData", "Hermit", "iA-Writer", "IBMPlexMono",
"Inconsolata", "InconsolataGo", "InconsolataLGC", "IntelOneMono", "Iosevka",
"IosevkaTerm", "IosevkaTermSlab", "JetBrainsMono", "Lekton", "LiberationMono",
"Lilex", "MartianMono", "Meslo", "Monaspace", "Monofur", "Monoid", "Mononoki",
"MPlus", "NerdFontsSymbolsOnly", "Noto", "OpenDyslexic", "Overpass", "ProFont",
"ProggyClean", "Recursive", "RobotoMono", "ShareTechMono", "SourceCodePro",
"SpaceMono", "Terminus", "Tinos", "Ubuntu", "UbuntuMono", "UbuntuSans", "VictorMono", "ZedMono"
)
# Display menu in columns like bash version
$ColumnCount = 4
$TotalFonts = $FontsList.Count
$RowCount = [Math]::Ceiling($TotalFonts / $ColumnCount)
for ($row = 0; $row -lt $RowCount; $row++) {
$line = ""
for ($col = 0; $col -lt $ColumnCount; $col++) {
$index = $row + ($col * $RowCount)
if ($index -lt $TotalFonts) {
$number = $index + 1
$fontName = $FontsList[$index]
$line += "{0,3}) {1,-20}" -f $number, $fontName
}
}
Write-Host $line
}
# Add Quit option
Write-Host ("{0,3}) {1}" -f ($TotalFonts + 1), "Quit")
Write-Host ""
# Get user selection
while ($true) {
$Selection = Read-Host "Enter a number"
# Validate input
if ($Selection -match '^\d+$') {
$Number = [int]$Selection
if ($Number -ge 1 -and $Number -le $TotalFonts) {
$SelectedFont = $FontsList[$Number - 1]
break
}
elseif ($Number -eq ($TotalFonts + 1)) {
Write-InfoMessage "Exiting..."
exit 0
}
}
Write-ErrorMessage "Please enter a valid number (1-$($TotalFonts + 1))"
}
Write-InfoMessage "Starting download $SelectedFont nerd font"
# Set up paths
$UserFontsPath = Join-Path $env:LOCALAPPDATA "Microsoft\Windows\Fonts"
$TempDir = Join-Path $env:TEMP "NerdFonts_$(Get-Random)"
$ZipPath = Join-Path $TempDir "$SelectedFont.zip"
$ExtractPath = Join-Path $TempDir $SelectedFont
# Create directories
try {
if (-not (Test-Path $UserFontsPath)) {
New-Item -Path $UserFontsPath -ItemType Directory -Force | Out-Null
Write-InfoMessage "Created fonts folder: $UserFontsPath"
}
New-Item -Path $TempDir -ItemType Directory -Force | Out-Null
Write-InfoMessage "Created temporary folder: $TempDir"
}
catch {
Write-ErrorMessage "Failed to create directories: $_"
exit 1
}
# Download font
$DownloadUrl = "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$SelectedFont.zip"
Write-InfoMessage "Downloading from: $DownloadUrl"
try {
# Use Invoke-WebRequest with progress
$ProgressPreference = 'Continue'
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath -UseBasicParsing
Write-SuccessMessage "Downloaded $SelectedFont.zip"
}
catch {
Write-ErrorMessage "Failed to download font: $_"
Remove-TempFiles -TempDir $TempDir
exit 1
}
# Extract font
Write-InfoMessage "Extracting $SelectedFont.zip"
try {
Expand-Archive -Path $ZipPath -DestinationPath $ExtractPath -Force
Write-SuccessMessage "Extracted font files"
}
catch {
Write-ErrorMessage "Failed to extract font: $_"
Remove-TempFiles -TempDir $TempDir
exit 1
}
# Install fonts to user directory
Write-InfoMessage "Installing fonts to $UserFontsPath"
try {
$FontFiles = Get-ChildItem -Path $ExtractPath -Include "*.ttf", "*.otf" -Recurse
if ($FontFiles.Count -eq 0) {
Write-ErrorMessage "No font files found in the extracted archive"
Remove-TempFiles -TempDir $TempDir
exit 1
}
$InstalledCount = 0
foreach ($FontFile in $FontFiles) {
$DestinationPath = Join-Path $UserFontsPath $FontFile.Name
Copy-Item -Path $FontFile.FullName -Destination $DestinationPath -Force
$InstalledCount++
}
Write-SuccessMessage "Installed $InstalledCount font file(s)"
}
catch {
Write-ErrorMessage "Failed to install fonts: $_"
Remove-TempFiles -TempDir $TempDir
exit 1
}
# Try to register fonts with Windows system
Register-WindowsFonts -FontsPath $ExtractPath
# Clean up temporary files
Remove-TempFiles -TempDir $TempDir
Write-SuccessMessage "Font installation completed!"
Write-InfoMessage "Fonts installed to: $UserFontsPath"
Write-InfoMessage "You may need to restart applications to see the new fonts."
}
catch {
Write-ErrorMessage "An unexpected error occurred: $_"
# Clean up on error
if ($TempDir -and (Test-Path $TempDir)) {
Remove-TempFiles -TempDir $TempDir
}
exit 1
}