Created
October 29, 2023 16:17
-
-
Save amigus/f4f2f528f6252ff0072ef85cb300b44c to your computer and use it in GitHub Desktop.
Install Nerd Fonts directly from the downloaded ZIP files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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