Skip to content

Commit

Permalink
fix setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jpawlowski committed Aug 27, 2024
1 parent fe12808 commit c0f2557
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/powershell-extended/Install-NerdFont.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
You will be prompted to confirm the installation for each font with the option to skip, cancel,
or install all without further confirmation.
.PARAMETER List
List available Nerd Fonts matching the specified pattern.
Use '*' or 'All' to list all available Nerd Fonts.
This parameter does not install any fonts.
.EXAMPLE
Install-NerdFont -Name cascadia-code
Install the Cascadia Code fonts from the Microsoft repository.
Expand All @@ -81,6 +86,10 @@
Install-NerdFont -All -WhatIf
Show what would happen if all fonts were installed.
.EXAMPLE
Install-NerdFont -List cascadia*
List all fonts with names starting with 'cascadia'.
.NOTES
This script must be run on your local machine, not in a container.
#>
Expand All @@ -93,7 +102,11 @@ param(
[Parameter(Mandatory = $false, ParameterSetName = 'ListOnly')]
[AllowNull()]
[AllowEmptyString()]
[string]$List = $null,
[ArgumentCompleter({
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
@('All') | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
})]
[string]$List,

[Parameter(Mandatory = $false, ParameterSetName = 'ByAll', HelpMessage = 'In which scope do you want to install the Nerd Font, AllUsers or CurrentUser?')]
[Parameter(Mandatory = $false, ParameterSetName = 'ByName', HelpMessage = 'In which scope do you want to install the Nerd Font, AllUsers or CurrentUser?')]
Expand Down Expand Up @@ -369,7 +382,7 @@ begin {
Name = $_.caskName
DisplayName = $_.imagePreviewFont
Description = $_.description
Source = $_.releaseUrl -replace '^(https?://)(?:[^/]+\.)*([^/]+\.[^/]+)/repos/([^/]+)/([^/]+).*', '$1$2/$3/$4'
SourceUrl = $_.releaseUrl -replace '^(https?://)(?:[^/]+\.)*([^/]+\.[^/]+)/repos/([^/]+)/([^/]+).*', '$1$2/$3/$4'
}
}
return
Expand Down Expand Up @@ -541,6 +554,23 @@ begin {
$invalidSelections += $index
}
}

if ($invalidSelections.Count -eq 0) {
# Check for conflicting fonts
$conflictingFonts = $validSelections | Group-Object -Property unpatchedName | Where-Object { $_.Count -gt 1 }
if ($conflictingFonts.Count -eq 0) {
return $validSelections.caskName
}
else {
foreach ($conflict in $conflictingFonts) {
$conflictNames = $conflict.Group | ForEach-Object { $_.imagePreviewFont }
Write-Host "Conflicting selection(s): $($conflictNames -join ', '). These fonts cannot be installed together because they share the same base font name." -ForegroundColor Red
}
}
}
else {
Write-Host "Invalid selection(s): $($invalidSelections -join ', '). Please enter valid numbers between 0 and $($Options.Length - 1) or 'q' to quit." -ForegroundColor Red
}
}
}

Expand Down Expand Up @@ -670,7 +700,13 @@ begin {
$Name = Show-Menu -Options $allNerdFonts
if ($Name -eq 'quit') {
Write-Host "Selection process canceled."
return
if ($null -eq $MyInvocation.InvocationName -or $MyInvocation.InvocationName -eq '') {
# Running as a script block
return
} else {
# Running as a standalone script
exit
}
}
} while (-not $Name)

Expand Down

0 comments on commit c0f2557

Please sign in to comment.