Skip to content

Skip download and extraction when a font is already installed and -Force is not set #70

@MariusStorhaug

Description

When a user re-runs Install-NerdFont -Name 'FiraCode' (for example after rerunning a setup script, or with -All on a partially-installed system), the function downloads and extracts the archive even if the font is already present. The actual install step inside Install-Font is a no-op without -Force, but the bandwidth and disk I/O leading up to it are spent regardless.

Request

Current experience

Re-running the command on a system where the font is already installed still downloads tens of megabytes per font and extracts each archive. The end state is unchanged.

Desired experience

When the font is already installed at the requested scope and -Force is not specified, Install-NerdFont skips the download and extraction phases entirely for that font and emits a clear verbose message ("already installed, skipping"). With -Force the current behavior is preserved.

Acceptance criteria

  • A font that is already installed at the requested scope is skipped end-to-end (no download, no extract, no install) when -Force is not used
  • -Force continues to overwrite/reinstall as today
  • The skip is logged at verbose level so users can see why no work happened
  • Bulk runs (-All) only download archives for fonts that actually need installing

Related

  • Get-Font — used to detect existing installations

Technical decisions

Detection: Use Get-Font -Scope $Scope once at the start of process to build a HashSet[string] of installed font family names. Match each candidate Nerd Font's name against the set with a single wildcard (<Name>*) since Nerd Fonts installs many family variants per archive.

Match granularity: A font is considered "installed" when at least one family matching <NerdFontName>* is present at the requested scope. This is intentionally permissive — partially-installed archives can be reinstalled with -Force.

Where the check goes: Immediately before the download step, inside the per-font loop. Keeps the diff small and localized.


Implementation plan

  • In src/functions/public/Install-NerdFont.ps1, after resolving $nerdFontsToInstall, call Get-Font -Scope $Scope once and store the family names in a HashSet[string] (case-insensitive)
  • Before the download step for each font, check whether any installed family matches <font.Name>*
  • If a match is found and -Force is not set, Write-Verbose "already installed, skipping" and continue
  • Add a Pester test that re-installs a font without -Force and asserts no download occurred (mock Invoke-WebRequest)
  • Add a Pester test that re-installs with -Force and asserts the download did occur

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions