1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2024-12-19 20:12:52 +02:00
nerd-fonts/install.ps1

63 lines
2.1 KiB
PowerShell
Raw Normal View History

#Requires -Version 3.0
<#
.SYNOPSIS
Installs the provided fonts.
.DESCRIPTION
Installs all the provided fonts by default. The FontName
parameter can be used to pick a subset of fonts to install.
.EXAMPLE
C:\PS> ./install.ps1
Installs all the fonts located in the Git repository.
.EXAMPLE
2021-01-27 02:21:16 +02:00
C:\PS> ./install.ps1 FiraCode, Hack
Installs all the FiraCode and Hack fonts.
.EXAMPLE
2021-01-27 02:21:16 +02:00
C:\PS> ./install.ps1 DejaVuSansMono -WhatIf
Shows which fonts would be installed without actually installing the fonts.
Remove the "-WhatIf" to install the fonts.
#>
[CmdletBinding(SupportsShouldProcess)]
param ()
2021-01-27 02:15:47 +02:00
dynamicparam {
$Attributes = [Collections.ObjectModel.Collection[Attribute]]::new()
$ParamAttribute = [Parameter]::new()
$ParamAttribute.Position = 0
$ParamAttribute.ParameterSetName = '__AllParameterSets'
$Attributes.Add($ParamAttribute)
2021-01-27 02:18:25 +02:00
[string[]]$FontNames = Join-Path $PSScriptRoot patched-fonts | Get-ChildItem -Directory -Name
2021-01-27 02:15:47 +02:00
$Attributes.Add([ValidateSet]::new(($FontNames)))
$Parameter = [Management.Automation.RuntimeDefinedParameter]::new('FontName', [string[]], $Attributes)
$RuntimeParams = [Management.Automation.RuntimeDefinedParameterDictionary]::new()
$RuntimeParams.Add('FontName', $Parameter)
return $RuntimeParams
}
2021-01-27 02:15:47 +02:00
end {
$FontName = $PSBoundParameters.FontName
if (-not $FontName) {$FontName = '*'}
$fontFiles = [Collections.Generic.List[System.IO.FileInfo]]::new()
2021-01-27 02:18:25 +02:00
Join-Path $PSScriptRoot patched-fonts | Push-Location
2021-01-27 02:15:47 +02:00
foreach ($aFontName in $FontName) {
Get-ChildItem $aFontName -Filter "*.ttf" -Recurse | Foreach-Object {$fontFiles.Add($_)}
Get-ChildItem $aFontName -Filter "*.otf" -Recurse | Foreach-Object {$fontFiles.Add($_)}
2021-01-27 02:15:47 +02:00
}
Pop-Location
$fonts = $null
foreach ($fontFile in $fontFiles) {
if ($PSCmdlet.ShouldProcess($fontFile.Name, "Install Font")) {
if (!$fonts) {
$shellApp = New-Object -ComObject shell.application
$fonts = $shellApp.NameSpace(0x14)
}
$fonts.CopyHere($fontFile.FullName)
}
}
}