|
| 1 | +install_nerd_fonts() { |
| 2 | + FONT_VERSION="v3.4.0" |
| 3 | + FONT_NAMES=("FiraCode" "Hack" "JetBrainsMono" "RobotoMono" "SourceCodePro" "NotoMono") |
| 4 | + echo "Downloading and installing Nerd Fonts..." |
| 5 | + mkdir -p "$FONT_DIR" |
| 6 | + for FONT_NAME in "${FONT_NAMES[@]}"; do |
| 7 | + FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/$FONT_VERSION/$FONT_NAME.zip" |
| 8 | + curl -fL "$FONT_URL" -o "$HOME/$FONT_NAME.zip" |
| 9 | + if [[ $? -ne 0 ]]; then |
| 10 | + echo "Download failed for $FONT_NAME. Please check your network connection or font name!" |
| 11 | + continue |
| 12 | + fi |
| 13 | + unzip -o "$HOME/$FONT_NAME.zip" -d "$FONT_DIR" |
| 14 | + rm -f "$HOME/$FONT_NAME.zip" |
| 15 | + echo "$FONT_NAME font installed to $FONT_DIR." |
| 16 | + done |
| 17 | + echo "All Nerd Fonts installation completed!" |
| 18 | +} |
| 19 | + |
| 20 | +install_linux_fonts() { |
| 21 | + FONT_DIR="$HOME/.local/share/fonts" |
| 22 | + install_nerd_fonts |
| 23 | + fc-cache -fv |
| 24 | +} |
| 25 | + |
| 26 | +install_macos_fonts() { |
| 27 | + FONT_DIR="$HOME/Library/Fonts" |
| 28 | + install_nerd_fonts |
| 29 | +} |
| 30 | + |
| 31 | +install_windows_fonts() { |
| 32 | + FONT_DIR="$LOCALAPPDATA/Microsoft/Windows/Fonts" |
| 33 | + install_nerd_fonts |
| 34 | + register_windows_fonts |
| 35 | +} |
| 36 | + |
| 37 | +register_windows_fonts() { |
| 38 | + powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ' |
| 39 | +$ErrorActionPreference = "Stop" |
| 40 | +$fontDir = Join-Path $env:LOCALAPPDATA "Microsoft\Windows\Fonts" |
| 41 | +$registryPath = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" |
| 42 | +Get-ChildItem -Path $fontDir -Include *.ttf,*.otf -Recurse | ForEach-Object { |
| 43 | + $fontType = if ($_.Extension -ieq ".otf") { "OpenType" } else { "TrueType" } |
| 44 | + $name = "$($_.BaseName) ($fontType)" |
| 45 | + New-ItemProperty -Path $registryPath -Name $name -Value $_.FullName -PropertyType String -Force | Out-Null |
| 46 | +} |
| 47 | +' |
| 48 | +} |
| 49 | + |
| 50 | +install_fonts() { |
| 51 | + local target="${1:-}" |
| 52 | + [[ -n "$target" ]] || target="$(default_pkg_target)" |
| 53 | + case "$target" in |
| 54 | + deepin|arch|termux) install_linux_fonts ;; |
| 55 | + windows) install_windows_fonts ;; |
| 56 | + macos) install_macos_fonts ;; |
| 57 | + *) |
| 58 | + echo "error: unknown font target: $target" >&2 |
| 59 | + return 1 |
| 60 | + ;; |
| 61 | + esac |
| 62 | +} |
0 commit comments