unzip all nerd-font zip archives in parent directory

This commit is contained in:
Baipyrus 2024-11-28 14:15:50 +01:00
parent d79c3bf43f
commit 05de50080a
2 changed files with 20 additions and 20 deletions

View File

@ -63,7 +63,8 @@ Write-Host "============================================" -ForegroundColor DarkG
# Installing Nerd Fonts
Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan
ProcessUrlFiles -source "$dotfilesRepo\nerd-fonts" -fileExt ".zip" -progress $false
UnzipAndInstall -source "$dotfilesRepo\nerd-fonts" -destination "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\"
Get-ChildItem -Path "$env:TMP\nerd-fonts-config" -Filter "*.zip" | `
ForEach-Object { InstallNerdFont -source $_.FullName }
# Final message
Write-Host "Windows setup complete!" -ForegroundColor Green

View File

@ -161,35 +161,34 @@ function ProcessUrlFiles
Pop-Location
}
# Function to expand zip archives and copy to destination paths
function UnzipAndInstall
# Function to unzip and install nerd fonts
function InstallNerdFont
{
param (
[string]$source,
[string]$destination
[string]$source
)
# Create temporary directory for unzip
$appname = $source.Split('\')[-1]
$tmpApp = "$env:TMP\$appname-config"
if (-not (Test-Path $tmpApp))
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
}
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($source)
$parent = $source -split '\\' | Select-Object -SkipLast 1 | Join-String -Separator '\'
$destination = "$parent\$fileName"
# Create destination directory
if (-not (Test-Path $destination))
{ New-Item -ItemType Directory -Path $destination | Out-Null
}
# Find all .url files in the source directory
$urlFiles = Get-ChildItem -Path $source -Filter '*.url'
# Extract contents of zip archive
Write-Host "Extracting archive $source to $destination..." -ForegroundColor Cyan
Expand-Archive $source -DestinationPath $destination | Out-Null
foreach ($file in $urlFiles)
# Install extracted fonts
$fontFiles = Get-ChildItem -Path $destination -Include "*.ttf", "*.otf"
foreach ($font in $fontFiles)
{
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
Write-Host "Extracting archive $tmpApp\$fileName.zip to $tmpApp\$fileName\..." -ForegroundColor Cyan
Expand-Archive "$tmpApp\$fileName.zip" -DestinationPath "$tmpApp\$fileName" | Out-Null
Write-Host "Installing fonts from $tmpApp\$fileName\ for current user..." -ForegroundColor Cyan
Copy-Item -Path "$tmpApp\$fileName\*" -Destination $destination -Force -ErrorAction SilentlyContinue
# TODO:
}
}
}
}