Skip to content

Instantly share code, notes, and snippets.

@BOAScripts
Created October 31, 2022 15:38
Show Gist options
  • Select an option

  • Save BOAScripts/4e3b11a76ba57829d44702fad7701a95 to your computer and use it in GitHub Desktop.

Select an option

Save BOAScripts/4e3b11a76ba57829d44702fad7701a95 to your computer and use it in GitHub Desktop.
Scripted installation of a NerdFont
# Setup tmp dir
$wrkDir = "$env:USERPROFILE\Desktop\TmpFonts"
New-Item $wrkDir -ItemType Directory | Out-Null
# Download
Write-Host -ForegroundColor DarkYellow "[I] Downloading fonts in $wrkDir"
$FontURL = "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.2.2/CascadiaCode.zip"
$DestFont = "$wrkDir\CaskaydiaCoveNF.zip"
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $FontURL -OutFile $DestFont
$ProgressPreference = 'Continue'
# Unpack
Expand-Archive $DestFont -DestinationPath "$wrkDir\CaskaydiaCoveNF"
Remove-Item $DestFont -Force
# Remove unnecessary files
$removeMe = @(
'Caskaydia Cove Nerd Font Complete Bold Italic.otf',
'Caskaydia Cove Nerd Font Complete Bold.otf',
'Caskaydia Cove Nerd Font Complete ExtraLight Italic.otf',
'Caskaydia Cove Nerd Font Complete ExtraLight.otf',
'Caskaydia Cove Nerd Font Complete Italic.otf',
'Caskaydia Cove Nerd Font Complete Light Italic.otf',
'Caskaydia Cove Nerd Font Complete Light.otf',
'Caskaydia Cove Nerd Font Complete Mono Bold Italic.otf',
'Caskaydia Cove Nerd Font Complete Mono Bold.otf',
'Caskaydia Cove Nerd Font Complete Mono ExtraLight Italic.otf',
'LICENSE',
'readme.md'
)
foreach ($item in (Get-ChildItem "$wrkDir\CaskaydiaCoveNF")){
if ($removeMe -contains $item.Name){
Remove-Item $item.FullName
}
}
# Install fonts
$registryKey = "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
$fontInstallDir = "$env:LOCALAPPDATA\Microsoft\Windows\Fonts"
New-Item $fontInstallDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
Get-ChildItem "$wrkDir\CaskaydiaCoveNF" | ForEach-Object {
$value = "$fontInstallDir\$($_.Name)"
New-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $value -Force | Out-Null
Copy-Item $_.FullName -Destination $fontInstallDir
}
# Cleanup
Remove-Item $wrkDir -Recurse
Write-Host -ForegroundColor DarkYellow "[I] CaskaydiaCodve NF font installed - tmp folder deleted"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment