-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathEdit-LineEnding.ps1
More file actions
43 lines (31 loc) · 845 Bytes
/
Edit-LineEnding.ps1
File metadata and controls
43 lines (31 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
enum LineEndingTypes {
Darwin
Unix
Win
}
function Edit-LineEnding {
[CmdletBinding(SupportsShouldProcess = $true)]
[OutputType([String[]])]
param (
[Parameter(ValueFromPipeline = $true)]
[String[]]$InputText,
[Parameter()][LineEndingTypes]$LineEnding = "Unix"
)
Begin {
Switch ("$LineEnding".ToLower()) {
"darwin" { $eol = "`r" }
"unix" { $eol = "`n" }
"win" { $eol = "`r`n" }
}
}
Process {
[String[]]$outputText += $InputText |
ForEach-Object { $_ -replace "`r`n", "`n" } |
ForEach-Object { $_ -replace "`r", "`n" } |
ForEach-Object { $_ -replace "`n", "$eol" }
}
End {
return $outputText
}
}
New-Alias -Name "Edit-LineEndings" -Value "Edit-LineEnding"