/EndOfLine

EndOfLine is a PowerShell module that automates conversion of end-of-line (EOL) characters in files.

Primary LanguagePowerShellMIT LicenseMIT

EndOfLine

Objective of this module is conversion of end-of-line (EOL) characters in UTF-8 files: CRLF to LF or LF to CRLF

GitHub license PS Gallery

Features

  • Imports .gitignore file for exclusion of files and directories, if there is a file. You can use SkipIgnoreFile switch to prevent importing that file. And you can switch Exclude to add additional items to be excluded.
  • Simulate what will happen via WhatIf switch
  • Outputs a report on all files. The Verbose switch can be used too.

Caveat

  • Please use the WhatIf switch parameter to perform a 'dry-run' on what files will be modified.
  • Files are expected to be encoded in UTF-8. If encoded in anything else it will not be modified.

Instructions

To install, run the following command in PowerShell.

$ Install-Module EndOfLine

This module imports 'Encoding' by Chris Kuech.

PS Gallery

Usage

ConvertTo-LF

ConvertTo-LF [-Path] <String[]> [[-Exclude] <String[]>]
[-SkipIgnoreFile] [-ExportReportData] [-WhatIf] [<CommonParameters>]

Converts CRLF to LF characters. This function will recursively read all files within the Path unless excluded by .gitignore file. If a file is not excluded it is read to see if the current EOL character is the same as requested. If so it will not modify the file. And if the file is encoded other then UTF-8, it will not be modified.

Example using the WhatIf, and Verbose switch.

$ ConvertTo-LF -Path C:\repos\AiT -WhatIf -Verbose

For this example, if you agree when prompted files will be modified without import of .gitignore file.

$ ConvertTo-LF -Path C:\repos\AiT -SkipIgnoreFile

If omitting gitignore file, it would be good to exclude modules too.

$ ConvertTo-LF -Path C:\repos\AiT -Exclude .\node_modules\, .\out\ -SkipIgnoreFile

If you agree when prompted, files will be modified with import of .gitignore file if found.

$ ConvertTo-LF -Path C:\repos\AiT

ConvertTo-CRLF

ConvertTo-CRLF [-Path] <String[]> [[-Exclude] <String[]>] 
[-SkipIgnoreFile] [-ExportReportData] [-WhatIf] [<CommonParameters>]

Converts LF to CRLF characters. Besides the characters that will be replaced, all things that apply in ConvertTo-LF apply to this function too.