From 4d2f9e5d54a98f58a4a543dc7cf87c254fa7d41e Mon Sep 17 00:00:00 2001 From: Freddie Sackur Date: Wed, 27 Jan 2021 00:18:25 +0000 Subject: [PATCH 1/2] Moved install.ps1 next to install.sh --- install.ps1 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 install.ps1 diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000000..cbff408e19 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,61 @@ +<# +.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 furamono-, hack-* + Installs all the FuraMono and Hack fonts. +.EXAMPLE + C:\PS> ./install.ps1 d* -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) + } + } +} From d4222fc149eb14a95b77a4e51a63b7324f32d056 Mon Sep 17 00:00:00 2001 From: Freddie Sackur Date: Wed, 27 Jan 2021 00:21:16 +0000 Subject: [PATCH 2/2] Updated examples --- install.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.ps1 b/install.ps1 index cbff408e19..a120850e78 100644 --- a/install.ps1 +++ b/install.ps1 @@ -8,10 +8,10 @@ C:\PS> ./install.ps1 Installs all the fonts located in the Git repository. .EXAMPLE - C:\PS> ./install.ps1 furamono-, hack-* - Installs all the FuraMono and Hack fonts. + C:\PS> ./install.ps1 FiraCode, Hack + Installs all the FiraCode and Hack fonts. .EXAMPLE - C:\PS> ./install.ps1 d* -WhatIf + C:\PS> ./install.ps1 DejaVuSansMono -WhatIf Shows which fonts would be installed without actually installing the fonts. Remove the "-WhatIf" to install the fonts. #>