Skip to content

Instantly share code, notes, and snippets.

@amigus
Created October 29, 2023 16:17
Show Gist options
  • Save amigus/f4f2f528f6252ff0072ef85cb300b44c to your computer and use it in GitHub Desktop.
Save amigus/f4f2f528f6252ff0072ef85cb300b44c to your computer and use it in GitHub Desktop.
Install Nerd Fonts directly from the downloaded ZIP files
<#
.SYNOPSIS
Install the 'Regular' fonts in Nerdfonts ZIP files
.DESCRIPTION
Extract NerdFont Zip files into a temporary directory and install the fonts
the fonts matching '-Regular' while filtering out the '-Mono' and '-Propo'
variants.
.EXAMPLE
Install-Nerdfonts.ps1 FiraCode.zip, LiberationMono.zip
.EXAMPLE
Get-Childitem -Path .\NerdFonts -Filter '*.zip' | Install-Nerdfonts.ps1
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)][ValidateNotNullOrEmpty()]
[string[]]$FontZip
)
begin {
$Fonts = (New-Object -ComObject Shell.Application).Namespace(20)
$TempFolderPath = [IO.Path]::GetTempPath() + "Nerdfonts"
if (Test-Path -PathType Container $TempFolderPath) {
Remove-Item -Path $TempFolderPath -Force -Recurse
}
New-Item -ItemType Directory $TempFolderPath
}
process {
$FontFolder = $TempFolderPath + '\' + (Get-Item $FontZip).BaseName
New-Item -ItemType Directory $FontFolder
Expand-Archive "${FontZip}" -DestinationPath $FontFolder -Force
Get-ChildItem -Recurse $FontFolder | Where-Object {
$_.Name -like '*-Regular.[ot]tf' -and
$_.Name -notlike '*Propo-*' -and
$_.Name -notlike '*Mono-*.*'
} | ForEach-Object {
$Fonts.CopyHere($_.FullName, 16)
}
}
end {
Remove-Item -Path $TempFolderPath -Force -Recurse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment