From 3b5887e0f9e1b75ccfbdb4f901c74ec4583ff7c7 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Fri, 24 Jul 2015 21:30:12 -0500 Subject: [PATCH 1/2] Change encoding of generated shim files to ASCII * change file encoding of the basic shim to be in a normal ASCII character set .# DISCUSSION Within PowerShell, `echo STRING > FILE` generates a file encoded in UCS-2-BOM format (or "Unicode", in PowerShell terminology). UCS-2 later morphed into the similar UTF-16 encoding format, and, within PowerShell, is treated as a "fuzzy equivalent" encoding. Problematically, these UCS-2 files are misinterpreted by CMD, which expects files using the ASCII (or "extended-ASCII") character encoding. And, in general, the UCS-2 format has many drawbacks when interpreted outside of a narrow PowerShell window. So, in general, it's best to stick to pure ASCII (or UTF-8, *without BOM*) encoded files, if at all possible. NOTE: ASCII (not "extended-ASCII") and UTF-8 (non-BOM) encoded files are exactly equivalent. NOTE: "Extended-ASCII" is poorly defined, requiring an associated Windows Code Page designation to firmly establish the encoding. ref: [Unicode UTF and BOM] http://www.unicode.org/faq/utf_bom.html @@ https://archive.is/TKnyk ref: [Unicode and NET] http://csharpindepth.com/Articles/General/Unicode.aspx @@ https://archive.is/czs89 --- lib/core.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 2728cb432..9b0376ad3 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -111,14 +111,14 @@ function shim($path, $global, $name, $arg) { $shim = "$abs_shimdir\$($name.tolower()).ps1" # note: use > for first line to replace file, then >> to append following lines - echo '# ensure $HOME is set for MSYS programs' > $shim - echo "if(!`$env:home) { `$env:home = `"`$home\`" }" >> $shim - echo 'if($env:home -eq "\") { $env:home = $env:allusersprofile }' >> $shim - echo "`$path = `"$path`"" >> $shim + echo '# ensure $HOME is set for MSYS programs' | out-file $shim -encoding oem + echo "if(!`$env:home) { `$env:home = `"`$home\`" }" | out-file $shim -encoding oem -append + echo 'if($env:home -eq "\") { $env:home = $env:allusersprofile }' | out-file $shim -encoding oem -append + echo "`$path = `"$path`"" | out-file $shim -encoding oem -append if($arg) { - echo "`$args = '$($arg -join "', '")', `$args" >> $shim + echo "`$args = '$($arg -join "', '")', `$args" | out-file $shim -encoding oem -append } - echo 'if($myinvocation.expectingInput) { $input | & $path @args } else { & $path @args }' >> $shim + echo 'if($myinvocation.expectingInput) { $input | & $path @args } else { & $path @args }' | out-file $shim -encoding oem -append if($path -match '\.exe$') { # for programs with no awareness of any shell From 1fbcd53f2de93237544e4dc17108e9575a89af32 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 20 Aug 2015 13:44:58 -0500 Subject: [PATCH 2/2] Remove now-erroneous comment --- lib/core.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index eaee9493a..f28d8f9f7 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -116,7 +116,6 @@ function shim($path, $global, $name, $arg) { $relative_path = resolve-path -relative $path popd - # note: use > for first line to replace file, then >> to append following lines echo '# ensure $HOME is set for MSYS programs' | out-file $shim -encoding oem echo "if(!`$env:home) { `$env:home = `"`$home\`" }" | out-file $shim -encoding oem -append echo 'if($env:home -eq "\") { $env:home = $env:allusersprofile }' | out-file $shim -encoding oem -append