workaround: open system font book to let user click 'Install'
[webi-installers/.git] / nerdfont / install.ps1
1 #!/bin/pwsh
2
3 $my_nerdfont_otf = "Droid Sans Mono for Powerline Nerd Font Complete Windows Compatible.otf"
4 $my_fontdir = "$Env:UserProfile\AppData\Local\Microsoft\Windows\Fonts"
5
6 New-Item -Path "$my_fontdir" -ItemType Directory -Force | out-null
7 IF (!(Test-Path -Path "$my_fontdir\$my_nerdfont_otf"))
8 {
9
10     & curl.exe -fsSLo "$my_nerdfont_otf" 'https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete
11 /Droid%20Sans%20Mono%20Nerd%20Font%20Complete%20Windows%20Compatible.otf'
12     & move "$my_nerdfont_otf" "$my_fontdir"
13 }
14
15
16 pushd "$my_fontdir"
17
18 $regFontPath = "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
19 $fontRegistryPath = "HKCU:$regFontPath"
20 $fontFiles = Get-ChildItem -Recurse -Include *.ttf, *.otf
21 foreach($font in $fontFiles) {
22     # See https://github.com/PPOSHGROUP/PPoShTools/blob/master/PPoShTools/Public/FileSystem/Add-Font.ps1#L80
23     Add-Type -AssemblyName System.Drawing
24     $objFontCollection = New-Object System.Drawing.Text.PrivateFontCollection
25     $objFontCollection.AddFontFile($font.FullName)
26     $FontName = $objFontCollection.Families.Name
27
28     $regTest = Get-ItemProperty -Path $fontRegistryPath -Name "*$FontName*" -ErrorAction SilentlyContinue
29     if (-not ($regTest)) {
30         New-ItemProperty -Name $FontName -Path $fontRegistryPath -PropertyType string -Value $font.Name
31         Write-Output "Registered font {$($font.Name)} in Current User registry as {$FontName}"
32     }
33     echo "Installed $my_nerdfont_otf to $my_fontdir"
34     # because adding to the registry alone doesn't actually take
35     & start $font.FullName
36     echo ""
37     echo "IMPORTANT: Click 'Install' to complete installation"
38 }