Skip to content

Commit 0a26c39

Browse files
feat: Get-Font ( Fixes #2 )
1 parent 054dda7 commit 0a26c39

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Commands/Get-Font.ps1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function Get-Font {
2+
<#
3+
.SYNOPSIS
4+
Gets Fonts
5+
.DESCRIPTION
6+
Gets currently installed fonts
7+
#>
8+
param()
9+
10+
$fontPaths =
11+
if ($IsLinux) {
12+
"/usr/share/fonts"
13+
"$home/.local/share/fonts"
14+
} elseif ($IsMacOS) {
15+
"/Library/Fonts"
16+
"$home/Library/Fonts"
17+
} else {
18+
"$env:WinDir\Fonts"
19+
"$($env:AppData |
20+
Split-Path |
21+
Join-Path -ChildPath 'Local\Microsoft\Windows\Fonts')"
22+
}
23+
24+
$fcList = $ExecutionContext.SessionState.invokecommand.GetCommand('fc-list', 'Application')
25+
26+
$fontFiles =
27+
if ($fcList) {
28+
& $fcList |
29+
ForEach-Object {
30+
$o = $_
31+
$file, $description = $o -split ':', 2
32+
$file -as [IO.FileInfo]
33+
} | Sort-Object FullName
34+
} else {
35+
$fontPaths |
36+
Get-ChildItem -Path { $_ } -ErrorAction Ignore -File -Recurse |
37+
Where-Object Extension -in '.svg', '.ttf', '.otf', '.t1', '.pfb'
38+
}
39+
40+
41+
foreach ($fontFile in $fontFiles) {
42+
if ($fontFile.Extension -notin '.svg','.ttf','.otf') {
43+
continue
44+
}
45+
$fontFile.pstypenames.add('Font.File')
46+
$fontFile
47+
}
48+
49+
}
50+

0 commit comments

Comments
 (0)