Skip to content

Commit

Permalink
✨ 🎨 Add char import; reorg script data
Browse files Browse the repository at this point in the history
  • Loading branch information
brianary committed Dec 8, 2023
1 parent 2ed7e49 commit 21d310d
Show file tree
Hide file tree
Showing 14 changed files with 73,880 additions and 73,789 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"markdown"
],
"[markdown]": {
"editor.defaultFormatter": "yzhang.markdown-all-in-one"
"editor.defaultFormatter": "darkriszty.markdown-table-prettify"
}
}
15 changes: 8 additions & 7 deletions Get-UnicodeByName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ for characters that support both a simple text presentation as well as a color e
)
Begin
{
$cc = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'cc.txt')) -Raw)
$codepoint = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Raw)
$html = Get-Content ([io.path]::ChangeExtension($PSCommandPath,'html.json')) -Raw |ConvertFrom-Json -AsHashtable
$github = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'github.txt')) -Raw)
$basename = Join-Path -Path $PSScriptRoot -ChildPath data -AdditionalChildPath UnicodeByName
$cc = ConvertFrom-StringData (Get-Content "$basename.cc.txt" -Raw)
$codepoint = ConvertFrom-StringData (Get-Content "$basename.txt" -Raw)
$html = Get-Content "$basename.html.json" -Raw |ConvertFrom-Json -AsHashtable
$github = ConvertFrom-StringData (Get-Content "$basename.github.txt" -Raw)
filter ConvertTo-Char([Parameter(ValueFromPipeline)][string] $Value)
{
$result = (($Value -split '\W+') |
Expand All @@ -81,12 +82,12 @@ Process
ForEach-Object {
if($_.OldName -and $_.Value -notin $conflictingOldNames){$_.OldName+'='+$_.Value}
if($_.Name -ne '<control>'){$_.Name+'='+$_.Value}
} |Out-File ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Encoding utf8
Invoke-WebRequest https://html.spec.whatwg.org/entities.json -OutFile ([io.path]::ChangeExtension($PSCommandPath,'html.json'))
} |Out-File "$basename.txt" -Encoding utf8
Invoke-WebRequest https://html.spec.whatwg.org/entities.json -OutFile "$basename.html.json"
(Invoke-RestMethod https://api.github.com/emojis).PSObject.Properties |
Where-Object {$_.Value -notlike "*/$($_.Name).png[?]v8"} |
ForEach-Object {':'+$_.Name+':='+(((([uri]$_.Value).Segments[-1]) -replace '\.png\z').ToUpper() -replace '-',',')} |
Out-File ([io.path]::ChangeExtension($PSCommandPath,'github.txt')) -Encoding utf8
Out-File "$basename.github.txt" -Encoding utf8
Write-Information 'Updated.'
return
}
Expand Down
22 changes: 21 additions & 1 deletion Get-UnicodeData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,36 @@ Returns the current (cached) Unicode character data.
.OUTPUTS
System.Management.Automation.PSCustomObject for each character entry with these properties:
* BidirectionalCategory
* Catgory
* CombiningClass
* Comment
* DecimalDigitValue
* DecompositionMapping
* DigitValue
* Lower
* Mirrored
* Name
* NumericValue
* OldName
* Title
* Upper
* Value
.FUNCTIONALITY
Unicode
.LINK
https://www.unicode.org/L2/L1999/UnicodeData.html
.EXAMPLE
Get-UnicodeData.ps1 |Export-Csv data/UnicodeData.csv
Saves the current Unicode data as a CSV file.
#>

#Requires -Version 7
[CmdletBinding()] Param(
[CmdletBinding()][OutputType([pscustomobject])] Param(
# The location of the latest Unicode data.
[uri] $Url = 'https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt',
[string] $DataFile = (Join-Path $env:TEMP ($Url.Segments[-1]))
Expand Down
7 changes: 4 additions & 3 deletions Get-UnicodeName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ SPACE
)
Begin
{
$cc = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'cc.txt')) -Raw)
$name = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Raw)
$basename = Join-Path -Path $PSScriptRoot -ChildPath data -AdditionalChildPath UnicodeName
$cc = ConvertFrom-StringData (Get-Content "$basename.cc.txt" -Raw)
$name = ConvertFrom-StringData (Get-Content "$basename.txt" -Raw)
}
Process
{
Expand All @@ -46,7 +47,7 @@ Process
$hex = '{0:X4}' -f $_.Value
$cc.ContainsKey($hex) ? $cc[$hex] : $_.Name
}} |
Export-Csv ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Delimiter '='
Export-Csv "$basename.txt" -Delimiter '='
Write-Information 'Updated.'
return
}
Expand Down
45 changes: 45 additions & 0 deletions Import-CharConstants.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<#
.SYNOPSIS
Imports characters by name as constants into the current scope.
.INPUTS
System.String containing a character name.
.FUNCTIONALITY
Unicode
.LINK
Add-ScopeLevel.ps1
.LINK
Get-UnicodeByName.ps1
.EXAMPLE
Import-CharConstants.ps1 NL :UP: HYPHEN-MINUS 'EN DASH' '&mdash;' '&copy;' -Scope Script
Creates constants in the context of the current script for the named characters.
#>

#Requires -Version 7
[CmdletBinding()] Param(
# The control code abbreviation, Unicode name, HTML entity, or GitHub name of the character to create a constant for.
# "NL" will use the newline appropriate to the environment.
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true,ValueFromRemainingArguments=$true)][string[]] $CharacterName,
# The scope of the constant.
[string] $Scope = 'Local',
<#
Appends a U+FE0F VARIATION SELECTOR-16 suffix to the character, which suggests an emoji presentation
for characters that support both a simple text presentation as well as a color emoji-style one.
#>
[switch] $AsEmoji
)
Begin {$level = Add-ScopeLevel.ps1 -Scope $Scope}
Process
{
foreach($name in $CharacterName)
{
$cname = $name -replace ':'
$value = $name -ceq 'NL' ? [Environment]::NewLine : (Get-UnicodeByName.ps1 -Name $name -AsEmoji:$AsEmoji)
Set-Variable -Name $cname -Value $value -Scope $level -Option Constant -Description $name
}
}
2 changes: 1 addition & 1 deletion New-PesterTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Begin
}
}
}
Set-Variable NL ([Environment]::NewLine) -Scope Script -Option Constant
Import-CharConstants.ps1 NL -Scope Script

filter Format-ExampleTest
{
Expand Down
43 changes: 26 additions & 17 deletions Update-Everything.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,28 @@ Attempts to update packages, features, and system.
Justification='This script is not intended for pipelining.')]
[CmdletBinding()] Param(
# The sources of updates to install, in order.
[ValidateSet('Chocolatey','DellCommand','Dotnet','Essential','GitHubCli','Npm',
[ValidateSet('Chocolatey','DellCommand','Dotnet','Essential','GitHubCli','Npm','ScriptsData',
'PSHelp','PSModule','Scoop','WindowsUpdate','WindowsStore','WinGet')]
[Parameter(Position=0,ValueFromRemainingArguments=$true)][string[]] $Steps =
@('Essential','WindowsStore','Scoop','Chocolatey','WinGet','Npm','Dotnet',
'GitHubCli','PSModule','PSHelp','DellCommand','WindowsUpdate')
'GitHubCli','ScriptsData','PSModule','PSHelp','DellCommand','WindowsUpdate')
)
Begin
{
Import-CharConstants.ps1 ':UP:' -Scope Script

function Test-EmptyDesktop([switch] $Shared)
{
if($Shared -and !(Test-Administrator.ps1)) {return $false}
$dir = [environment]::GetFolderPath(($Shared ? 'CommonDesktopDirectory' : 'Desktop' ))
return !(Get-ChildItem -Path $dir -Filter *.lnk)
return !(Join-Path $dir *.lnk |Get-Item)
}

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

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

function Invoke-EssentialUpdate
{
Write-Step "${UP!} Updating PowerShell & Windows Terminal"
Write-Step "$UP Updating PowerShell & Windows Terminal"
Get-Process powershell -ErrorAction Ignore |Where-Object Id -ne $PID |Stop-Process -Force
Get-Process pwsh -ErrorAction Ignore |Where-Object Id -ne $PID |Stop-Process -Force
Start-Process ([io.path]::ChangeExtension($PSCommandPath,'cmd')) -Verb RunAs -WindowStyle Maximized
Expand Down Expand Up @@ -159,7 +161,7 @@ Begin
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping WindowsStore."; return}
if(!(Get-Command Get-CimInstance -ErrorAction Ignore))
{Write-Verbose 'Get-CimInstance not found, skipping WindowsStore updates'; return}
Write-Step "${UP!} Updating Windows Store apps (asynchronously)"
Write-Step "$UP Updating Windows Store apps (asynchronously)"
Get-CimInstance MDM_EnterpriseModernAppManagement_AppManagement01 -Namespace root\cimv2\mdm\dmmap |
Invoke-CimMethod -MethodName UpdateScanMethod
}
Expand All @@ -168,7 +170,7 @@ Begin
{
if(!(Get-Command scoop -ErrorAction Ignore))
{Write-Verbose 'Scoop not found, skipping'; return}
Write-Step "${UP!} Updating Scoop packages"
Write-Step "$UP Updating Scoop packages"
scoop update *
}

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

function Update-WinGet
{
if(!(Get-Command winget -ErrorAction Ignore))
{Write-Verbose 'WinGet not found, skipping'; return}
Write-Step "${UP!} Updating WinGet packages"
Write-Step "$UP Updating WinGet packages"
winget upgrade --all
}

function Update-Npm
{
if(!(Get-Command npm -ErrorAction Ignore))
{Write-Verbose 'Npm not found, skipping'; return}
Write-Step "${UP!} Updating npm packages"
Write-Step "$UP Updating npm packages"
npm update -g
}

function Update-Dotnet
{
if(!(Get-Command dotnet -ErrorAction Ignore))
{Write-Verbose 'Dotnet not found, skipping'; return}
Write-Step "${UP!} Updating dotnet global tools"
Write-Step "$UP Updating dotnet global tools"
& "$PSScriptRoot\Get-DotNetGlobalTools.ps1" |
Where-Object {
$_.Version -lt (& "$PSScriptRoot\Find-DotNetGlobalTools.ps1" $_.PackageName |
Expand All @@ -214,13 +216,13 @@ Begin
{
if(!(Get-Command gh -ErrorAction Ignore))
{Write-Verbose 'gh not found, skipping'; return}
Write-Step "${UP!} Updating GitHub CLI extensions"
Write-Step "$UP Updating GitHub CLI extensions"
gh extension upgrade --all
}

function Update-PSModule
{
Write-Step "${UP!} Updating PowerShell modules"
Write-Step "$UP Updating PowerShell modules"
Get-Module -ListAvailable |
Group-Object Name |
Where-Object {
Expand All @@ -231,23 +233,30 @@ Begin
Update-Module -Force
if(Get-Command Uninstall-OldModules.ps1 -ErrorAction Ignore)
{
Write-Step "${UP!} Uninstalling old PowerShell modules"
Write-Step "$UP Uninstalling old PowerShell modules"
Uninstall-OldModules.ps1 -Force
}
}

function Update-PSHelp
{
Write-Step "${UP!} Updating PowerShell help"
Write-Step "$UP Updating PowerShell help"
Update-Help
}

function Update-ScriptsData
{
Write-Step "$UP Updating scripts data"
Get-UnicodeName.ps1 -Update
Get-UnicodeByName.ps1 -Update
}

function Update-DellCommand
{
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping DellCommand."; return}
if(!(Resolve-Path "C:\Program Files*\Dell\CommandUpdate\dcu-cli.exe"))
{Write-Verbose 'Dell Command not found, skipping'; return}
Write-Step "${UP!} Updating Dell firmware & system software"
Write-Step "$UP Updating Dell firmware & system software"
Set-Alias dcu-cli "$(Resolve-Path "C:\Program Files*\Dell\CommandUpdate\dcu-cli.exe")"
dcu-cli /scan
if($LASTEXITCODE -ne 500) {dcu-cli /applyUpdates -reboot=enable}
Expand All @@ -259,7 +268,7 @@ Begin
if(!(Test-Administrator.ps1)) {Write-Warning "Not running as admin; skipping Windows."; return}
if(!(Get-Module PSWindowsUpdate -ListAvailable))
{Write-Verbose 'PSWindowsUpdate module not found, skipping Windows Updates'; return}
Write-Step "${UP!} Updating Windows"
Write-Step "$UP Updating Windows"
Get-WindowsUpdate
Install-WindowsUpdate |Format-Table X,Result,KB,Size,Title
}
Expand Down
Loading

0 comments on commit 21d310d

Please sign in to comment.