From f699edfbad1386221377920381247bcced6930b2 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Thu, 1 Sep 2016 19:12:31 -0600 Subject: [PATCH] Add help and FontName parameter. This commit allows the user to specify a subset of fonts to install e.g. ./install.ps1 fura-*,hack-* will install all the FuraMono and Hack fonts. Support for the -WhatIf parameter was also added so you can see what fonts would be installed (without actually installing the fonts). --- install.ps1 | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/install.ps1 b/install.ps1 index 2f388c4..b16cfa9 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,3 +1,41 @@ -$sa = new-object -comobject shell.application -$fonts = $sa.NameSpace(0x14) -gci $PSScriptRoot -i *.ttf, *.otf -Recurse | %{$fonts.CopyHere($_.FullName)} +<# +.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( + # Specifies the font name to install. Default value will install all fonts. + [Parameter(Position=0)] + [string[]] + $FontName = '*' +) + +$fontFiles = New-Object 'System.Collections.Generic.List[System.IO.FileInfo]' +foreach ($aFontName in $FontName) { + Get-ChildItem $PSScriptRoot -Filter "${aFontName}.ttf" -Recurse | Foreach-Object {$fontFiles.Add($_)} + Get-ChildItem $PSScriptRoot -Filter "${aFontName}.otf" -Recurse | Foreach-Object {$fontFiles.Add($_)} +} + +$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) + } +}