diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000000..a120850e78 --- /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 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) + } + } +} diff --git a/patched-fonts/install.ps1 b/patched-fonts/install.ps1 deleted file mode 100644 index b16cfa9577..0000000000 --- a/patched-fonts/install.ps1 +++ /dev/null @@ -1,41 +0,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 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) - } -} diff --git a/readme.md b/readme.md index 71642e725c..931eba4cfd 100644 --- a/readme.md +++ b/readme.md @@ -221,6 +221,12 @@ _Note_: **Requires cloning** the repo as of now ./install.sh ``` +or, in Powershell (Windows only): + +```pwsh +./install.ps1 +``` + #### Single font: * Installs a single Font of your choice @@ -231,6 +237,14 @@ _Note_: **Requires cloning** the repo as of now ./install.sh HeavyData ``` +or, in Powershell (Windows only): + +```pwsh +./install.ps1 +./install.ps1 Hack +./install.ps1 HeavyData +``` + ### `Option 4: Homebrew Fonts` > Best option if on **macOS** and want to use **Homebrew**.