Nerd-fonts: An install script for Windows

Created on 15 Dec 2017  ·  15Comments  ·  Source: ryanoasis/nerd-fonts

So I've been wondering, why this project doesn't have an install script for Windows like similar projects (See https://github.com/powerline/fonts/blob/master/install.ps1 or https://github.com/gabrielelana/awesome-terminal-fonts/blob/master/install.ps1).

With there now being an Unbuntu bash shell for Windows, and this project having Windows compatible fonts, I've been curious as to why there isn't a script to install the Windows compatible fonts for Windows.

24PullRequests help wanted windows up-for-grabs ☕ discussion ✋ question ➤ future

Most helpful comment

Scoop offers some fonts in the nerd-fonts bucket, and it's not hard (example) to add more. Installation is as simple as:

One-time: $ scoop bucket add nerd-fonts
Each-font: $ scoop install DejaVuSansMono-NF

All 15 comments

@jrcharney First of all, thank you for bringing this up, it's something I haven't really thought much about so it is a valuable topic. So you mean adding a PowerShell script for the install?

There is no good reason we don't have one or couldn't :smile:

Some reasons why we don't right currently: I don't really use Windows for development purposes, a contributor submitted a PR for the initial install script and it has been dramatically expanded on since then. Basically we try to be community driven, so if the demand is high enough for an install script that works with WIndows we would be all for it.

One thing I am not familiar on yet is the windows bash shell. Would we have to write and support an entire powershell install script similar to the bash one or can we just create a wrapper to call it? Because the one thing I noticed about the 2 scripts you referenced is that they are fairly short but the current install script in Nerd Fonts is fairly large. Even then wouldn't that just be compatible with Windows 10 only?

Those are my thoughts :smile:

Well, I don't have much experience with writing scripts for the powershell, but it looks pretty easy. In fact, I still have one of the scripts from another package that I had used for installing fonts with but have since decided NerdFonts would be the better option.

Out of curiousity, should I just instruct the script to look for all the fonts in each font family package with the words "Windows Compatible" in them, or should I install every font in each package?

Also worth considering, if I am using Ubuntu for Windows (which works way better this year than when it intially came out last year), and I am wondering if there is a way to show the difference between using the regular NerdFonts, the NerdFonts meant for Powerline (which also can be used with Airline, which I like much better because it is written in Vimscript not Python), and the NerdFonts that are Windows Compatible? I think it might be ideal to group each of those together in each font package such that the install scripts (both for Linux/Unix/Mac and Windows) can be installed without having to go through the hassle of applying Regular Expression to search for which files to install.

It would definitely be useful for a Windows install script to make the necessary Registry edit to add the font to the list of blessed fonts at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont for terminal use.

(I seriously have no idea why Microsoft don't let the user pick any monospaced font they've installed, but doubtless there's some reason for it…)

I'm trying to add FuraCode manually right now, and it's by no means clear whether I should put "Fira Code", "FiraCode-Regular", "FuraCode", "Furacode NF Regular", or whatever — and with a reboot required for the changes to take effect (it's like Windows 95 never went away!) it's a long process. Automation would definitely help people out here.

(UPDATE: apparently, none of those options are right. If anybody could tell me what Registry entry to make so I can use this font in the Ubuntu subsystem, that would really help!)

@unikitty37, tinkering with RegEdit really is not necessary.

It should be noted, that I am now using WSLTTY instead of the actual shell that Bash for Ubuntu for Windows now comes with. Apparently BUW is still using Windows's conhost.exe (which may as well be cmd.exe), which DOES NOT support the patched glyphs. WSLTTY does support the glyphs.

Here's what it looks like with my Zsh shell using Powerlevel9k.

BUW
image

WSLTTY
image

Hey! Look! Transparency! WSLTTY FTW!

At any rate, I'm hoping to push my P9K Zsh theme to one of my repos in the near future. It only seemed right for Orange and Plum to be used for Ubuntu.

How about distributing with https://chocolatey.org/ ? It is similar to brew on OS X

Chocolatey looks like a good bet

Scoop offers some fonts in the nerd-fonts bucket, and it's not hard (example) to add more. Installation is as simple as:

One-time: $ scoop bucket add nerd-fonts
Each-font: $ scoop install DejaVuSansMono-NF

There doesn't seem to be a "great" way to do it, but after adding the bucket, you can search for -NF
PS > scoop search "-NF"
Then copy that list to a text editor and delete the whitespace before, and use search and replace to get rid of anything after the -NF. There are probably better ways, but I searched for -NF.*$ and replaced it with -NF. Create a here-string in PS and add this list to it.

PS > $fonts = @'
3270-NF
...
UbuntuMono-NF
'@

Then split the list and pipe it for install:
PS > $fonts -Split "`n" | ForEach-Object {scoop install $_}

I'm sure there is much I could do to improve this process, but as a first stab, this seems to make it pretty easy to get up and going. @pakdev, thanks for the tip and maybe this is something you can use @ryanoasis.

After a few painful hours, I found that the PowerShell script "install.ps1" in the repository of Powerline Fonts works on Nerd Fonts too with the instruction here. I put the script under the patched-fonts folder.

@LZong-tw,

I put the script under the patched-fonts folder. It'd be great if the repo just had all that was needed instead of having to try and recreate what you accomplished.

Do you have a PR out to contribute this?

@rbeesley

Do you have a PR out to contribute this?

Oh, I just forgot to do it. I've just made one a few moments ago.

This was done in #357 forgot to update the issue, thanks @LZong-tw

I found no method of reliably automating the installation of these fonts to Windows in the project documentation along with the Terminal-Icons module to enable these fonts on gci / dir / ls output in PowerShell so wrote the below. The following can be thrown into any PowerShell console (with Admin rights) and should set everything up.

### Install Terminal-Icons (get LiterationMono NF Nerd font, install, add required Console registry key, then install required Modules)
$url = 'https://github.com/haasosaurus/nerd-fonts/raw/regen-mono-font-fix/patched-fonts/LiberationMono/complete/Literation%20Mono%20Nerd%20Font%20Complete%20Mono%20Windows%20Compatible.ttf'
$name = "LiterationMono NF"
$file = "$($env:TEMP)\$($name).ttf"
Start-BitsTransfer -Source $url -Destination $file   # Download the font

$Install = $true  # $false to uninstall (or 1 / 0)
$FontsFolder = (New-Object -ComObject Shell.Application).Namespace(0x14)   # Must use Namespace part or will not install properly
$filename = (Get-ChildItem $file).Name
$filepath = (Get-ChildItem $file).FullName
$target = "C:\Windows\Fonts\$($filename)"

If (Test-Path $target -PathType Any) { Remove-Item $target -Recurse -Force } # UnInstall Font

If ((-not(Test-Path $target -PathType Container)) -and ($Install -eq $true)) { $FontsFolder.CopyHere($filepath, 16) }   # Following action performs the install, requires user to click on yes

$key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont'   # Need to set this for console
Set-ItemProperty -Path $key -Name '000' -Value $name

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force   # Always need this, required for all Modules
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted   # Set Microsoft PowerShell Gallery to 'Trusted'
Install-Module Terminal-Icons -Scope CurrentUser
Import-Module Terminal-Icons
Install-Module WindowsConsoleFonts
Set-ConsoleFont $name
Set-TerminalIconsColorTheme -Name DevBlackOps   # After the above are setup, can add this to Profile to always load

This script work fine but only after being executed every time I start up my shell. Is there a way to make it the default config?
(No problem in my powershell in vscode btw)

Edit: Never mind... I just read the last comment and it's all good ^^

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brontosaurusrex picture brontosaurusrex  ·  4Comments

MartinDelille picture MartinDelille  ·  4Comments

laughedelic picture laughedelic  ·  5Comments

ffernand picture ffernand  ·  4Comments

lilyball picture lilyball  ·  5Comments