Skip to content

Instantly share code, notes, and snippets.

@markekraus
Last active September 20, 2017 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markekraus/7c019b19377e61a1c40dee3ba1e90801 to your computer and use it in GitHub Desktop.
Save markekraus/7c019b19377e61a1c40dee3ba1e90801 to your computer and use it in GitHub Desktop.
Sorts .spelling file for Powershel/Powershell
$File = (Get-Content .\.spelling)
$Head = $File[0..4]
$Count = 0
$Dictionary = foreach($Line in $File[5..($File.Count -1)]){
$Count ++
if($Line -Match '^#region ' -or [string]::IsNullOrEmpty($line)){continue}
if($line -match '^ -|^#endregion'){break}
$line
}
$Dictionary = $Dictionary | Sort-Object
$OverridesStart = $Head.Count + $Count
$Overrides = @{}
foreach($Line in $File[$OverridesStart..($File.Count - 1)]){
if($Line -Match '^#region |^#endregion' -or [string]::IsNullOrEmpty($line)){continue}
if($line -match '^ -'){
$List = [System.Collections.Generic.List[string]]::new()
$Overrides[$line] = $List
}
else{
$List.Add(($Line -replace '^-', '_ZZZZ'))
}
}
$Rest = $Overrides.Keys | Sort-Object | ForEach-Object {
'#region {0} Overrides' -f ($_ -replace ' - ')
$_
$Overrides[$_].Sort()
$Overrides[$_] | ForEach-Object { $_ -replace '^_ZZZZ', '-' }
'#endregion'
''
}
$Head,
'',
'#region Global Dictionary',
$Dictionary,
'#endregion',
'',
$Rest[0..($Rest.count - 2)] | Set-Content .\.spelling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment