跳转至

macOS 批量安装Nerd Font

概要: 使用brew工具在macOS上批量安装Nerd Font

创建时间: 2022.11.20 21:39:25

更新时间: 2022.11.20 21:58:24

什么是Nerd Font

Nerd Font 相比于传统的字体,支持了更多的符号和图标显示,可用于 oh-my-zsh 的高级主题(如 romkatv/powerlevel10k: A Zsh theme),效果如下(图源官网)
sankey-glyphs-combined-diagram.svg

使用brew安装Nerd Font

配置 cask-fonts

Bash
brew tap homebrew/cask-fonts

搜索 Nerd Font

使用如下命令可以搜索到全部的Nerd Font,为便于安装比对,将搜索结果输出到 brew-nerd-fonts.txt 文件中

Bash
brew search nerd-font > brew-nerd-fonts.txt

安装单个 Nerd Font

在上面输出的 brew-nerd-fonts.txt 文件中,可以自由选择安装的 Nerd Font,如 FiraCode Nerd Font,使用如下命令安装

Bash
brew install font-fira-code-nerd-font

批量安装 Nerd Font

首先写一个简单的 shell 脚本 install-fonts.sh ,内容如下

Bash
1
2
3
4
5
6
7
#!/bin/sh

for line in `cat ~/brew-nerd-fonts.txt`
do
    echo "Installing font:  $line"
    brew install $line
done
然后赋予可执行权限
Bash
chmod +x ./install-fonts.sh
接下来是漫长的安装过程,请确保网络连接通畅
Bash
./install-fonts.sh

检查已安装Nerd Fonts

Bash
brew search nerd-font
image.png
画上对勾的表明已安装完毕,注意如果IDE需要使用刚刚安装的字体,可能需要重启软件

参考