Feature: Add -WindowsCompatibleOnly switch parameter to install.ps1

Fixes: #840
This commit is contained in:
Evan Reed 2022-06-02 16:38:09 -04:00 committed by Fini
parent 1d21ef9e79
commit 539eb92138

View file

@ -11,13 +11,19 @@
.EXAMPLE .EXAMPLE
C:\PS> ./install.ps1 FiraCode, Hack C:\PS> ./install.ps1 FiraCode, Hack
Installs all the FiraCode and Hack fonts. Installs all the FiraCode and Hack fonts.
.EXAMPLE
C:\PS> ./install.ps1 CascadiaCode -WindowsCompatibleOnly
Filters fonts to include only those labeled as 'Windows Compatible'
Can be used in combination with the -FontName and/or -WhatIf parameters
.EXAMPLE .EXAMPLE
C:\PS> ./install.ps1 DejaVuSansMono -WhatIf C:\PS> ./install.ps1 DejaVuSansMono -WhatIf
Shows which fonts would be installed without actually installing the fonts. Shows which fonts would be installed without actually installing the fonts.
Remove the "-WhatIf" to install the fonts. Remove the "-WhatIf" to install the fonts.
#> #>
[CmdletBinding(SupportsShouldProcess)] [CmdletBinding(SupportsShouldProcess)]
param () param (
[switch]$WindowsCompatibleOnly
)
dynamicparam { dynamicparam {
$Attributes = [Collections.ObjectModel.Collection[Attribute]]::new() $Attributes = [Collections.ObjectModel.Collection[Attribute]]::new()
@ -44,8 +50,17 @@ end {
Join-Path $PSScriptRoot patched-fonts | Push-Location Join-Path $PSScriptRoot patched-fonts | Push-Location
foreach ($aFontName in $FontName) { foreach ($aFontName in $FontName) {
Get-ChildItem $aFontName -Filter "*.ttf" -Recurse | Foreach-Object {$fontFiles.Add($_)} Get-ChildItem $aFontName -Recurse | Where-Object {
Get-ChildItem $aFontName -Filter "*.otf" -Recurse | Foreach-Object {$fontFiles.Add($_)} $IsValidFileExtension = $_.Extension -match 'ttf|otf'
if ($WindowsCompatibleOnly) {
$IsValidFileExtension -and ($_.BaseName -match 'Windows Compatible')
} else {
$IsValidFileExtension
}
} | ForEach-Object {
$fontFiles.Add($_)
}
} }
Pop-Location Pop-Location