Skip to content

Instantly share code, notes, and snippets.

@davidteren
Last active February 1, 2025 23:46
Show Gist options
  • Save davidteren/898f2dcccd42d9f8680ec69a3a5d350e to your computer and use it in GitHub Desktop.
Save davidteren/898f2dcccd42d9f8680ec69a3a5d350e to your computer and use it in GitHub Desktop.
Install Nerd Fonts via Homebrew [updated & fixed]

Nerd Fonts for your IDE

https://www.nerdfonts.com/font-downloads

The following solution thanks to @hackerzgz & @snacky101 will install all nerd fonts;

brew tap homebrew/cask-fonts
brew search '/font-.*-nerd-font/' | awk '{ print $1 }' | xargs -I{} brew install --cask {} || true

If you prefer to explicitly list the nerd fonts you want to install then you can use the solution provided by @frame45

#!/bin/bash

fonts_list=(
  font-3270-nerd-font
  font-fira-mono-nerd-font
  font-inconsolata-go-nerd-font
  font-inconsolata-lgc-nerd-font
  font-inconsolata-nerd-font
  font-monofur-nerd-font
  font-overpass-nerd-font
  font-ubuntu-mono-nerd-font
  font-agave-nerd-font
  font-arimo-nerd-font
  font-anonymice-nerd-font
  font-aurulent-sans-mono-nerd-font
  font-bigblue-terminal-nerd-font
  font-bitstream-vera-sans-mono-nerd-font
  font-blex-mono-nerd-font
  font-caskaydia-cove-nerd-font
  font-code-new-roman-nerd-font
  font-cousine-nerd-font
  font-daddy-time-mono-nerd-font
  font-dejavu-sans-mono-nerd-font
  font-droid-sans-mono-nerd-font
  font-fantasque-sans-mono-nerd-font
  font-fira-code-nerd-font
  font-go-mono-nerd-font
  font-gohufont-nerd-font
  font-hack-nerd-font
  font-hasklug-nerd-font
  font-heavy-data-nerd-font
  font-hurmit-nerd-font
  font-im-writing-nerd-font
  font-iosevka-nerd-font
  font-jetbrains-mono-nerd-font
  font-lekton-nerd-font
  font-liberation-nerd-font
  font-meslo-lg-nerd-font
  font-monoid-nerd-font
  font-mononoki-nerd-font
  font-mplus-nerd-font
  font-noto-nerd-font
  font-open-dyslexic-nerd-font
  font-profont-nerd-font
  font-proggy-clean-tt-nerd-font
  font-roboto-mono-nerd-font
  font-sauce-code-pro-nerd-font
  font-shure-tech-mono-nerd-font
  font-space-mono-nerd-font
  font-terminess-ttf-nerd-font
  font-tinos-nerd-font
  font-ubuntu-nerd-font
  font-victor-mono-nerd-font
)

brew tap homebrew/cask-fonts

for font in "${fonts_list[@]}"
do
  brew install --cask "$font"
done
exit
@mhmdcs
Copy link

mhmdcs commented Jul 5, 2024

If you're getting the error:
Error: homebrew/cask-fonts was deprecated. This tap is now empty and all its contents were either deleted or migrated
When running brew tap homebrew/cask-fonts, it's because in May 16, 2024 the fonts previously available in homebrew/cask-fonts have been moved to the main homebrew/cask repository. So you can just directly install any fonts you want without tapping.

@ivanluelmo
Copy link

brew search '/font-.*-nerd-font/' | awk '{ print $1 }' | xargs brew install --cask

@snacky101 Thanks a lot !! I was looking for this. (No need to tap anymore in August 2024)

@amritapathak89
Copy link

amritapathak89 commented Aug 16, 2024

Yes, as of Aug 2024, no need to tap anymore. Installing a particular font, is as simple as
brew install --cask font-ubuntu-nerd-font

@louwers
Copy link

louwers commented Sep 29, 2024

You don't even need --cask.

brew install font-ubuntu-nerd-font works.

@ckuhtz
Copy link

ckuhtz commented Oct 16, 2024

brew search '/font-.*-nerd-font/' | awk '{ print $1 }' | xargs brew install --cask

@snacky101 Thanks a lot !! I was looking for this. (No need to tap anymore in August 2024)

Is there a way to create a keyword for homebrew that installs all nerd fonts rather than having to resort to this? ;-) something that is the equivalent of brew install nerd-fonts-all

@qwe-kev
Copy link

qwe-kev commented Oct 17, 2024

Yes, as of Aug 2024, no need to tap anymore. Installing a particular font, is as simple as brew install --cask font-ubuntu-nerd-font

@amritapathak89 Thanks a bunch!

@zx0r
Copy link

zx0r commented Jan 22, 2025

#!/usr/bin/env bash

# Script: install_nerd_fonts.sh
# Description: A script to interactively select and install Nerd Fonts for macOS using Homebrew and fzf.
# Author: zx0r
# Version: 1.0

# Enable strict error handling
set -euo pipefail

# Constants
FZF_PROMPT="Select Nerd Fonts: "
FZF_HEIGHT="60%"
FZF_LAYOUT="reverse"

# Colors
BLACK='\033[0;30m'  # Black
RED='\033[0;31m'    # Red
GREEN='\033[0;32m'  # Green
YELLOW='\033[0;33m' # Yellow
BLUE='\033[0;34m'   # Blue
PURPLE='\033[0;35m' # Purple
CYAN='\033[0;36m'   # Cyan
NC='\033[0m'        # Text Reset

# Function to check if a command is installed
is_command_installed() {
  command -v "$1" &>/dev/null
}

# Function to print a step message
print_step() {
  echo -e "\n${CYAN}${1}${NC}\n"
}

# Function to print a success message
print_success() {
  echo -e "\n${GREEN}${1}${NC}\n"
}

# Function to print a warning message
print_warn() {
  echo -e "${YELLOW}[Warn] ${1}${NC}"
}

# Function to print an error message and exit
print_error() {
  echo -e "${RED}❗️${1}${NC}"
  exit 1
}

# Function to check for dependencies
check_dependencies() {
  local dependencies=("brew" "fzf")

  for dep in "${dependencies[@]}"; do
    if ! is_command_installed "$dep"; then
      print_warn "$dep is not installed."
      if [[ "$dep" == "brew" ]]; then
        print_warn "Please install Homebrew first: https://brew.sh"
      elif [[ "$dep" == "fzf" ]]; then
        print_step "Installing fzf..."
        brew install fzf
      fi
      exit 1
    fi
  done
}

# Function to fetch available Nerd Fonts
fetch_nerd_fonts() {
  brew search '/font-.*-nerd-font/' | awk '{ print $1 }'
}

# Function to select fonts interactively using fzf
select_fonts() {
  local fonts="$1"
  echo "$fonts" | fzf --multi --prompt="$FZF_PROMPT" --height="$FZF_HEIGHT" --layout="$FZF_LAYOUT"
}

# Function to install selected fonts
install_fonts() {
  local selected_fonts="$1"
  if [[ -z "$selected_fonts" ]]; then
    print_warn "No fonts selected. Exiting."
    exit 0
  fi

  print_step "Installing selected Nerd Fonts..."
  # Use a while loop to handle font names with spaces
  echo "$selected_fonts" | while read -r font; do
    echo -e "Installing $font..."
    if brew install --cask "$font"; then
      print_success "Successfully installed $font."
    else
      print_warn "Failed to install $font."
    fi
  done
}

# Main function to orchestrate the script
main() {
  print_step "Select the Nerd Fonts you want to install (use TAB to select multiple):"

  check_dependencies

  local fonts
  fonts=$(fetch_nerd_fonts)
  if [[ -z "$fonts" ]]; then
    print_error "No Nerd Fonts found. Please ensure Homebrew is up to date."
  fi

  local selected_fonts
  selected_fonts=$(select_fonts "$fonts")

  install_fonts "$selected_fonts"
}

# Run the script
main

@oregonpillow
Copy link

oregonpillow commented Jan 24, 2025

Thanks @snacky101 for the inspiration
For anyone that is Ansible inclined:

- name: Collect nerd font names
  shell: brew search '/font-.*-nerd-font/' | awk '{ print $1 }' | xargs
  register: nerd_fonts
  changed_when: false

- name: Install nerd fonts
  community.general.homebrew_cask:
    name: "{{ nerd_fonts.stdout | split }}"
    state: present
    update_homebrew: false
    upgrade_all: false
    install_options: no-quarantine
    sudo_password: "{{ my_sudo_password }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment