Last active
September 20, 2017 23:40
-
-
Save markekraus/7c019b19377e61a1c40dee3ba1e90801 to your computer and use it in GitHub Desktop.
Sorts .spelling file for Powershel/Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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