Skip to content

Commit 21d310d

Browse files
committed
✨ 🎨 Add char import; reorg script data
1 parent 2ed7e49 commit 21d310d

14 files changed

+73880
-73789
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"markdown"
2323
],
2424
"[markdown]": {
25-
"editor.defaultFormatter": "yzhang.markdown-all-in-one"
25+
"editor.defaultFormatter": "darkriszty.markdown-table-prettify"
2626
}
2727
}

Get-UnicodeByName.ps1

+8-7
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ for characters that support both a simple text presentation as well as a color e
5757
)
5858
Begin
5959
{
60-
$cc = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'cc.txt')) -Raw)
61-
$codepoint = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Raw)
62-
$html = Get-Content ([io.path]::ChangeExtension($PSCommandPath,'html.json')) -Raw |ConvertFrom-Json -AsHashtable
63-
$github = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'github.txt')) -Raw)
60+
$basename = Join-Path -Path $PSScriptRoot -ChildPath data -AdditionalChildPath UnicodeByName
61+
$cc = ConvertFrom-StringData (Get-Content "$basename.cc.txt" -Raw)
62+
$codepoint = ConvertFrom-StringData (Get-Content "$basename.txt" -Raw)
63+
$html = Get-Content "$basename.html.json" -Raw |ConvertFrom-Json -AsHashtable
64+
$github = ConvertFrom-StringData (Get-Content "$basename.github.txt" -Raw)
6465
filter ConvertTo-Char([Parameter(ValueFromPipeline)][string] $Value)
6566
{
6667
$result = (($Value -split '\W+') |
@@ -81,12 +82,12 @@ Process
8182
ForEach-Object {
8283
if($_.OldName -and $_.Value -notin $conflictingOldNames){$_.OldName+'='+$_.Value}
8384
if($_.Name -ne '<control>'){$_.Name+'='+$_.Value}
84-
} |Out-File ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Encoding utf8
85-
Invoke-WebRequest https://html.spec.whatwg.org/entities.json -OutFile ([io.path]::ChangeExtension($PSCommandPath,'html.json'))
85+
} |Out-File "$basename.txt" -Encoding utf8
86+
Invoke-WebRequest https://html.spec.whatwg.org/entities.json -OutFile "$basename.html.json"
8687
(Invoke-RestMethod https://api.github.com/emojis).PSObject.Properties |
8788
Where-Object {$_.Value -notlike "*/$($_.Name).png[?]v8"} |
8889
ForEach-Object {':'+$_.Name+':='+(((([uri]$_.Value).Segments[-1]) -replace '\.png\z').ToUpper() -replace '-',',')} |
89-
Out-File ([io.path]::ChangeExtension($PSCommandPath,'github.txt')) -Encoding utf8
90+
Out-File "$basename.github.txt" -Encoding utf8
9091
Write-Information 'Updated.'
9192
return
9293
}

Get-UnicodeData.ps1

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,36 @@ Returns the current (cached) Unicode character data.
44
55
.OUTPUTS
66
System.Management.Automation.PSCustomObject for each character entry with these properties:
7+
* BidirectionalCategory
8+
* Catgory
9+
* CombiningClass
10+
* Comment
11+
* DecimalDigitValue
12+
* DecompositionMapping
13+
* DigitValue
14+
* Lower
15+
* Mirrored
16+
* Name
17+
* NumericValue
18+
* OldName
19+
* Title
20+
* Upper
21+
* Value
722
823
.FUNCTIONALITY
924
Unicode
1025
1126
.LINK
1227
https://www.unicode.org/L2/L1999/UnicodeData.html
28+
29+
.EXAMPLE
30+
Get-UnicodeData.ps1 |Export-Csv data/UnicodeData.csv
31+
32+
Saves the current Unicode data as a CSV file.
1333
#>
1434

1535
#Requires -Version 7
16-
[CmdletBinding()] Param(
36+
[CmdletBinding()][OutputType([pscustomobject])] Param(
1737
# The location of the latest Unicode data.
1838
[uri] $Url = 'https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt',
1939
[string] $DataFile = (Join-Path $env:TEMP ($Url.Segments[-1]))

Get-UnicodeName.ps1

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ SPACE
3232
)
3333
Begin
3434
{
35-
$cc = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'cc.txt')) -Raw)
36-
$name = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Raw)
35+
$basename = Join-Path -Path $PSScriptRoot -ChildPath data -AdditionalChildPath UnicodeName
36+
$cc = ConvertFrom-StringData (Get-Content "$basename.cc.txt" -Raw)
37+
$name = ConvertFrom-StringData (Get-Content "$basename.txt" -Raw)
3738
}
3839
Process
3940
{
@@ -46,7 +47,7 @@ Process
4647
$hex = '{0:X4}' -f $_.Value
4748
$cc.ContainsKey($hex) ? $cc[$hex] : $_.Name
4849
}} |
49-
Export-Csv ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Delimiter '='
50+
Export-Csv "$basename.txt" -Delimiter '='
5051
Write-Information 'Updated.'
5152
return
5253
}

Import-CharConstants.ps1

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<#
2+
.SYNOPSIS
3+
Imports characters by name as constants into the current scope.
4+
5+
.INPUTS
6+
System.String containing a character name.
7+
8+
.FUNCTIONALITY
9+
Unicode
10+
11+
.LINK
12+
Add-ScopeLevel.ps1
13+
14+
.LINK
15+
Get-UnicodeByName.ps1
16+
17+
.EXAMPLE
18+
Import-CharConstants.ps1 NL :UP: HYPHEN-MINUS 'EN DASH' '&mdash;' '&copy;' -Scope Script
19+
20+
Creates constants in the context of the current script for the named characters.
21+
#>
22+
23+
#Requires -Version 7
24+
[CmdletBinding()] Param(
25+
# The control code abbreviation, Unicode name, HTML entity, or GitHub name of the character to create a constant for.
26+
# "NL" will use the newline appropriate to the environment.
27+
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true,ValueFromRemainingArguments=$true)][string[]] $CharacterName,
28+
# The scope of the constant.
29+
[string] $Scope = 'Local',
30+
<#
31+
Appends a U+FE0F VARIATION SELECTOR-16 suffix to the character, which suggests an emoji presentation
32+
for characters that support both a simple text presentation as well as a color emoji-style one.
33+
#>
34+
[switch] $AsEmoji
35+
)
36+
Begin {$level = Add-ScopeLevel.ps1 -Scope $Scope}
37+
Process
38+
{
39+
foreach($name in $CharacterName)
40+
{
41+
$cname = $name -replace ':'
42+
$value = $name -ceq 'NL' ? [Environment]::NewLine : (Get-UnicodeByName.ps1 -Name $name -AsEmoji:$AsEmoji)
43+
Set-Variable -Name $cname -Value $value -Scope $level -Option Constant -Description $name
44+
}
45+
}

New-PesterTests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Begin
4848
}
4949
}
5050
}
51-
Set-Variable NL ([Environment]::NewLine) -Scope Script -Option Constant
51+
Import-CharConstants.ps1 NL -Scope Script
5252

5353
filter Format-ExampleTest
5454
{

Update-Everything.ps1

+26-17
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,28 @@ Attempts to update packages, features, and system.
8888
Justification='This script is not intended for pipelining.')]
8989
[CmdletBinding()] Param(
9090
# The sources of updates to install, in order.
91-
[ValidateSet('Chocolatey','DellCommand','Dotnet','Essential','GitHubCli','Npm',
91+
[ValidateSet('Chocolatey','DellCommand','Dotnet','Essential','GitHubCli','Npm','ScriptsData',
9292
'PSHelp','PSModule','Scoop','WindowsUpdate','WindowsStore','WinGet')]
9393
[Parameter(Position=0,ValueFromRemainingArguments=$true)][string[]] $Steps =
9494
@('Essential','WindowsStore','Scoop','Chocolatey','WinGet','Npm','Dotnet',
95-
'GitHubCli','PSModule','PSHelp','DellCommand','WindowsUpdate')
95+
'GitHubCli','ScriptsData','PSModule','PSHelp','DellCommand','WindowsUpdate')
9696
)
9797
Begin
9898
{
99+
Import-CharConstants.ps1 ':UP:' -Scope Script
100+
99101
function Test-EmptyDesktop([switch] $Shared)
100102
{
101103
if($Shared -and !(Test-Administrator.ps1)) {return $false}
102104
$dir = [environment]::GetFolderPath(($Shared ? 'CommonDesktopDirectory' : 'Desktop' ))
103-
return !(Get-ChildItem -Path $dir -Filter *.lnk)
105+
return !(Join-Path $dir *.lnk |Get-Item)
104106
}
105107

106108
function Clear-Desktop([switch] $Shared)
107109
{
108110
if($Shared -and !(Test-Administrator.ps1)) {return}
109111
$dir = [environment]::GetFolderPath(($Shared ? 'CommonDesktopDirectory' : 'Desktop' ))
110-
Remove-Item -Path $dir -Filter *.lnk
112+
Remove-Item (Join-Path $dir *.lnk)
111113
}
112114

113115
Set-Variable 'UP!' "$([char]0xD83C)$([char]0xDD99)" -Option Constant -Scope Script -Description 'UP! symbol'
@@ -119,7 +121,7 @@ Begin
119121

120122
function Invoke-EssentialUpdate
121123
{
122-
Write-Step "${UP!} Updating PowerShell & Windows Terminal"
124+
Write-Step "$UP Updating PowerShell & Windows Terminal"
123125
Get-Process powershell -ErrorAction Ignore |Where-Object Id -ne $PID |Stop-Process -Force
124126
Get-Process pwsh -ErrorAction Ignore |Where-Object Id -ne $PID |Stop-Process -Force
125127
Start-Process ([io.path]::ChangeExtension($PSCommandPath,'cmd')) -Verb RunAs -WindowStyle Maximized
@@ -159,7 +161,7 @@ Begin
159161
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping WindowsStore."; return}
160162
if(!(Get-Command Get-CimInstance -ErrorAction Ignore))
161163
{Write-Verbose 'Get-CimInstance not found, skipping WindowsStore updates'; return}
162-
Write-Step "${UP!} Updating Windows Store apps (asynchronously)"
164+
Write-Step "$UP Updating Windows Store apps (asynchronously)"
163165
Get-CimInstance MDM_EnterpriseModernAppManagement_AppManagement01 -Namespace root\cimv2\mdm\dmmap |
164166
Invoke-CimMethod -MethodName UpdateScanMethod
165167
}
@@ -168,7 +170,7 @@ Begin
168170
{
169171
if(!(Get-Command scoop -ErrorAction Ignore))
170172
{Write-Verbose 'Scoop not found, skipping'; return}
171-
Write-Step "${UP!} Updating Scoop packages"
173+
Write-Step "$UP Updating Scoop packages"
172174
scoop update *
173175
}
174176

@@ -177,31 +179,31 @@ Begin
177179
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping Chocolatey."; return}
178180
if(!(Get-Command choco -ErrorAction Ignore))
179181
{Write-Verbose 'Chocolatey not found, skipping'; return}
180-
Write-Step "${UP!} Updating Chocolatey packages"
182+
Write-Step "$UP Updating Chocolatey packages"
181183
choco upgrade all -y
182184
}
183185

184186
function Update-WinGet
185187
{
186188
if(!(Get-Command winget -ErrorAction Ignore))
187189
{Write-Verbose 'WinGet not found, skipping'; return}
188-
Write-Step "${UP!} Updating WinGet packages"
190+
Write-Step "$UP Updating WinGet packages"
189191
winget upgrade --all
190192
}
191193

192194
function Update-Npm
193195
{
194196
if(!(Get-Command npm -ErrorAction Ignore))
195197
{Write-Verbose 'Npm not found, skipping'; return}
196-
Write-Step "${UP!} Updating npm packages"
198+
Write-Step "$UP Updating npm packages"
197199
npm update -g
198200
}
199201

200202
function Update-Dotnet
201203
{
202204
if(!(Get-Command dotnet -ErrorAction Ignore))
203205
{Write-Verbose 'Dotnet not found, skipping'; return}
204-
Write-Step "${UP!} Updating dotnet global tools"
206+
Write-Step "$UP Updating dotnet global tools"
205207
& "$PSScriptRoot\Get-DotNetGlobalTools.ps1" |
206208
Where-Object {
207209
$_.Version -lt (& "$PSScriptRoot\Find-DotNetGlobalTools.ps1" $_.PackageName |
@@ -214,13 +216,13 @@ Begin
214216
{
215217
if(!(Get-Command gh -ErrorAction Ignore))
216218
{Write-Verbose 'gh not found, skipping'; return}
217-
Write-Step "${UP!} Updating GitHub CLI extensions"
219+
Write-Step "$UP Updating GitHub CLI extensions"
218220
gh extension upgrade --all
219221
}
220222

221223
function Update-PSModule
222224
{
223-
Write-Step "${UP!} Updating PowerShell modules"
225+
Write-Step "$UP Updating PowerShell modules"
224226
Get-Module -ListAvailable |
225227
Group-Object Name |
226228
Where-Object {
@@ -231,23 +233,30 @@ Begin
231233
Update-Module -Force
232234
if(Get-Command Uninstall-OldModules.ps1 -ErrorAction Ignore)
233235
{
234-
Write-Step "${UP!} Uninstalling old PowerShell modules"
236+
Write-Step "$UP Uninstalling old PowerShell modules"
235237
Uninstall-OldModules.ps1 -Force
236238
}
237239
}
238240

239241
function Update-PSHelp
240242
{
241-
Write-Step "${UP!} Updating PowerShell help"
243+
Write-Step "$UP Updating PowerShell help"
242244
Update-Help
243245
}
244246

247+
function Update-ScriptsData
248+
{
249+
Write-Step "$UP Updating scripts data"
250+
Get-UnicodeName.ps1 -Update
251+
Get-UnicodeByName.ps1 -Update
252+
}
253+
245254
function Update-DellCommand
246255
{
247256
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping DellCommand."; return}
248257
if(!(Resolve-Path "C:\Program Files*\Dell\CommandUpdate\dcu-cli.exe"))
249258
{Write-Verbose 'Dell Command not found, skipping'; return}
250-
Write-Step "${UP!} Updating Dell firmware & system software"
259+
Write-Step "$UP Updating Dell firmware & system software"
251260
Set-Alias dcu-cli "$(Resolve-Path "C:\Program Files*\Dell\CommandUpdate\dcu-cli.exe")"
252261
dcu-cli /scan
253262
if($LASTEXITCODE -ne 500) {dcu-cli /applyUpdates -reboot=enable}
@@ -259,7 +268,7 @@ Begin
259268
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping Windows."; return}
260269
if(!(Get-Module PSWindowsUpdate -ListAvailable))
261270
{Write-Verbose 'PSWindowsUpdate module not found, skipping Windows Updates'; return}
262-
Write-Step "${UP!} Updating Windows"
271+
Write-Step "$UP Updating Windows"
263272
Get-WindowsUpdate
264273
Install-WindowsUpdate |Format-Table X,Result,KB,Size,Title
265274
}

0 commit comments

Comments
 (0)