Description
Summary of the new feature / enhancement
I work with source code and files for cross-platform projects that are standardized to all UNIX line endings (LF) instead of "historical Windows" (CR LF) (Notepad.Exe supports LF only since 2018)
My files are kept on shared filesystems that are accessed simultaneously by Windows, Linux, and MacOS systems.
Where possible I use bash for Windows when scripting, falling back on CMD.EXE occasionally. Yet increasingly PowerShell is needed, e.g. deprecations of things like ODBCCONF.EXE means I have to access "cmdlets" like Add-OdbcDsn
.
But there appears to be no way to ask Powershell not to use CR LF line endings on Windows when doing redirects. In piping it will translate incoming LF to CR LF, which also leads to binary file corruption (see #1908)
Personally I never want this on any platform. I consider LF endings canon, and certainly prefer no-op pipes produce the same bytes they get in.
However, I'd assume that a global setting asking for LF on Windows always would break expectations of some packaged functionality. That functionality is why I'm using PowerShell in the first place, so no good.
Proposed technical implementation details
I propose an OPTIONAL mode of operation in which the LF / CR LF usage of the source code of the running powershell script itself dictate its behavior. If the script source is LF-only, then it thinks it lives in an LF-only world and likely wants to live by LF-only expectations for piping. If the script is CR LF, then its redirection and piping favor that.
This would allow PowerShell's behavior to piggy-back on the existing git setting for autocrlf translation that cross-platform developers already use. Windows users who turn it on probably want CR LF in redirects when they run a script. Windows users who turn it off probably want just LF on their filesystem always.
I don't know how something like Add-OdbcDsn
works, but if it did piping on some .INI file that is CR LF based on Windows, my hope would be it would still work under this strategy...as a library script presumably is a CR LF file itself. So I could use a packaged piece of functionality like that in a script which itself was written to use LF only.
Maybe if it this option worked out well it could someday become a default. It would mean less conditional code between the Unix and Windows versions. As a first step I'd like it fine as something I could turn on globally and leave on.