forked from ryanoasis/nerd-fonts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
62 lines (54 loc) · 2.1 KB
/
install.ps1
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
#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
C:\PS> ./install.ps1 FiraCode, Hack
Installs all the FiraCode and Hack fonts.
.EXAMPLE
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 ()
dynamicparam {
$Attributes = [Collections.ObjectModel.Collection[Attribute]]::new()
$ParamAttribute = [Parameter]::new()
$ParamAttribute.Position = 0
$ParamAttribute.ParameterSetName = '__AllParameterSets'
$Attributes.Add($ParamAttribute)
[string[]]$FontNames = Join-Path $PSScriptRoot patched-fonts | Get-ChildItem -Directory -Name
$Attributes.Add([ValidateSet]::new(($FontNames)))
$Parameter = [Management.Automation.RuntimeDefinedParameter]::new('FontName', [string[]], $Attributes)
$RuntimeParams = [Management.Automation.RuntimeDefinedParameterDictionary]::new()
$RuntimeParams.Add('FontName', $Parameter)
return $RuntimeParams
}
end {
$FontName = $PSBoundParameters.FontName
if (-not $FontName) {$FontName = '*'}
$fontFiles = [Collections.Generic.List[System.IO.FileInfo]]::new()
Join-Path $PSScriptRoot patched-fonts | Push-Location
foreach ($aFontName in $FontName) {
Get-ChildItem $aFontName -Filter "*.ttf" -Recurse | Foreach-Object {$fontFiles.Add($_)}
Get-ChildItem $aFontName -Filter "*.otf" -Recurse | Foreach-Object {$fontFiles.Add($_)}
}
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)
}
}
}