Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/font_install_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Font Install Test

on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]

jobs:
test-install:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Ensure script is executable
run: chmod +x ./install_fonts.sh

- name: Run install_fonts.sh
run: ./install_fonts.sh
79 changes: 79 additions & 0 deletions install_fonts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# install_fonts.sh - Download and install the latest FiraCode Nerd Font
# Supports Linux, macOS, and Windows (via PowerShell)

set -euo pipefail

# Determine OS
OS_TYPE="$(uname -s)"
case "$OS_TYPE" in
Linux*) OS="Linux" ;;
Darwin*) OS="Mac" ;;
CYGWIN*|MINGW*|MSYS*) OS="Windows" ;;
*) echo "Unsupported OS: $OS_TYPE" >&2; exit 1 ;;
esac

# Font configuration
FONT_NAME="FiraCode"
ASSET_NAME="${FONT_NAME}.zip"
DOWNLOAD_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${ASSET_NAME}"

# Temporary directories
TMP_DIR="$(mktemp -d)"
ZIP_PATH="${TMP_DIR}/${ASSET_NAME}"
EXTRACT_DIR="${TMP_DIR}/extracted"

# Cleanup function
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT

echo "Downloading ${FONT_NAME} Nerd Font..."
curl -L -o "$ZIP_PATH" "$DOWNLOAD_URL"

echo "Extracting font archive..."
mkdir -p "$EXTRACT_DIR"
unzip -q "$ZIP_PATH" -d "$EXTRACT_DIR"

# Determine install directory based on OS
case "$OS" in
Linux)
FONT_DIR="${HOME}/.local/share/fonts"
;;
Mac)
FONT_DIR="${HOME}/Library/Fonts"
;;
Windows)
# PowerShell will handle the destination path
FONT_DIR="$(powershell -NoProfile -Command \"[System.Environment]::GetFolderPath('LocalApplicationData')\")\\Microsoft\\Windows\\Fonts"
;;
esac

echo "Installing fonts to ${FONT_DIR}..."
mkdir -p "$FONT_DIR"

# Copy .ttf and .otf files
shopt -s nullglob
FONT_FILES=("$EXTRACT_DIR"/*.ttf "$EXTRACT_DIR"/*.otf)
if [ ${#FONT_FILES[@]} -eq 0 ]; then
echo "No font files found in the archive." >&2
exit 1
fi

if [ "$OS" = "Windows" ]; then
# Use PowerShell to copy files (handles Windows path quirks)
for f in "${FONT_FILES[@]}"; do
powershell -NoProfile -Command "Copy-Item -Path '$(cygpath -w "$f")' -Destination '${FONT_DIR}' -Force"
done
else
cp "${FONT_FILES[@]}" "$FONT_DIR/"
fi

# Refresh font cache on Linux
if [ "$OS" = "Linux" ]; then
echo "Refreshing font cache..."
fc-cache -f "$FONT_DIR"
fi

echo "Font installation completed successfully."
Loading