@@ -13,24 +13,37 @@ public static void Handle(TextWriter output, ShellType shellType)
13
13
switch ( shellType )
14
14
{
15
15
case ShellType . Bash :
16
- PrintToConsoleFrom ( output , "dotnet-suggest-shim.bash" ) ;
16
+ PrintToConsoleFrom ( output , "dotnet-suggest-shim.bash" , useUnixLineEndings : true ) ;
17
17
break ;
18
18
case ShellType . PowerShell :
19
- PrintToConsoleFrom ( output , "dotnet-suggest-shim.ps1" ) ;
19
+ PrintToConsoleFrom ( output , "dotnet-suggest-shim.ps1" , useUnixLineEndings : false ) ;
20
20
break ;
21
21
case ShellType . Zsh :
22
- PrintToConsoleFrom ( output , "dotnet-suggest-shim.zsh" ) ;
22
+ PrintToConsoleFrom ( output , "dotnet-suggest-shim.zsh" , useUnixLineEndings : true ) ;
23
23
break ;
24
24
default :
25
25
throw new SuggestionShellScriptException ( $ "Shell '{ shellType } ' is not supported.") ;
26
26
}
27
27
}
28
28
29
- private static void PrintToConsoleFrom ( TextWriter output , string scriptName )
29
+ private static void PrintToConsoleFrom ( TextWriter output , string scriptName , bool useUnixLineEndings )
30
30
{
31
31
var assemblyLocation = Assembly . GetAssembly ( typeof ( SuggestionShellScriptHandler ) ) . Location ;
32
32
var directory = Path . GetDirectoryName ( assemblyLocation ) ;
33
- output . Write ( File . ReadAllText ( Path . Combine ( directory , scriptName ) ) ) ;
33
+ string scriptContent = File . ReadAllText ( Path . Combine ( directory , scriptName ) ) ;
34
+ bool hasUnixLineEndings = ! scriptContent . Contains ( "\r \n " ) ;
35
+ if ( hasUnixLineEndings != useUnixLineEndings )
36
+ {
37
+ if ( useUnixLineEndings )
38
+ {
39
+ scriptContent = scriptContent . Replace ( "\r \n " , "\n " ) ;
40
+ }
41
+ else
42
+ {
43
+ scriptContent = scriptContent . Replace ( "\n " , "\r \n " ) ;
44
+ }
45
+ }
46
+ output . Write ( scriptContent ) ;
34
47
}
35
48
}
36
49
}
0 commit comments