lipkau / PsIni

Work with INI files in PowerShell using hashtables
http://lipkau.github.io/PsIni
MIT License
151 stars 50 forks source link

Preserve White Space #38

Closed ghost closed 6 years ago

ghost commented 6 years ago

Would it be possible to preserve whitespace between sections?

For example, before the script touches an INI file, it could look like this:

[Category1]
Key1=Value1
Key2=Value2

[Category2]
Key1=Value1
Key2=Value2

[Category3]
Key1=Value1
Key2=Value2

[Category4]
Key1=Value1
Key2=Value2

After the script is done, all the white space is gone:

[Category1]
Key1=Value1
Key2=Value2
[Category2]
Key1=Value1
Key2=Value2
[Category3]
Key1=Value1
Key2=Value2
[Category4]
Key1=Value1
Key2=Value2

Makes readability more difficult after batch-editing a bunch of INIs.

ghost commented 6 years ago

Figured something out. It's not perfect, but it's better than it was.

Line 228 of Out-File.ps1:

if ($i -ne $script:NoSection) { Add-Content -Value "`r`n[$i]" @parameters }

Was:

if ($i -ne $script:NoSection) { Add-Content -Value "`n[$i]" @parameters }

Note the missing carriage return. This adds a line at the top of the file, too, but that's not a big deal.

lipkau commented 6 years ago

Hi @mtthwjrgnsn

Thank you for the suggestion.

I will definitely not preserve them, as that would mean I had to track and store them when reading the input file. I will however add a -Pretty parameter to Out-IniFile. How this helps you