From 05de50080a95851968cd6d3346a11eacc9639207 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Thu, 28 Nov 2024 14:15:50 +0100 Subject: [PATCH] unzip all nerd-font zip archives in parent directory --- install_windows.ps1 | 3 ++- util/windows.psm1 | 37 ++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/install_windows.ps1 b/install_windows.ps1 index 14708c6..fd9e77d 100644 --- a/install_windows.ps1 +++ b/install_windows.ps1 @@ -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 diff --git a/util/windows.psm1 b/util/windows.psm1 index c6e8bfb..b246ed2 100644 --- a/util/windows.psm1 +++ b/util/windows.psm1 @@ -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: + } +} + } }