@@ -31,24 +31,26 @@ stackframe_lineinfo_color() = repl_color("JULIA_STACKFRAME_LINEINFO_COLOR", :bol
3131stackframe_function_color () = repl_color (" JULIA_STACKFRAME_FUNCTION_COLOR" , :bold )
3232
3333function repl_cmd (cmd, out)
34- shell = shell_split (get (ENV , " JULIA_SHELL" , get (ENV , " SHELL" , " /bin/sh" )))
34+ shell_env = get (ENV , " JULIA_SHELL" , nothing )
35+ if shell_env === nothing || isempty (shell_env)
36+ shell_env = Sys. iswindows () ? " cmd" : get (ENV , " SHELL" , " /bin/sh" )
37+ end
38+ shell = shell_split (shell_env)
3539 shell_name = Base. basename (shell[1 ])
40+ Sys. iswindows () && (shell_name = lowercase (splitext (shell_name)[1 ])) # canonicalize for comparisons below
3641
3742 # Immediately expand all arguments, so that typing e.g. ~/bin/foo works.
3843 cmd. exec .= expanduser .(cmd. exec)
44+ isempty (cmd. exec) && throw (ArgumentError (" no cmd to execute" ))
3945
40- if isempty (cmd. exec)
41- throw (ArgumentError (" no cmd to execute" ))
42- elseif cmd. exec[1 ] == " cd"
46+ if cmd. exec[1 ] == " cd"
4347 new_oldpwd = pwd ()
4448 if length (cmd. exec) > 2
4549 throw (ArgumentError (" cd method only takes one argument" ))
4650 elseif length (cmd. exec) == 2
4751 dir = cmd. exec[2 ]
4852 if dir == " -"
49- if ! haskey (ENV , " OLDPWD" )
50- error (" cd: OLDPWD not set" )
51- end
53+ ! haskey (ENV , " OLDPWD" ) && error (" cd: OLDPWD not set" )
5254 cd (ENV [" OLDPWD" ])
5355 else
5456 @static if ! Sys. iswindows ()
@@ -66,19 +68,51 @@ function repl_cmd(cmd, out)
6668 ENV [" OLDPWD" ] = new_oldpwd
6769 println (out, pwd ())
6870 else
69- @static if ! Sys. iswindows ()
71+ local command
72+ if Sys. iswindows ()
73+ if shell_name == " cmd"
74+ _CMD_execute (cmd)
75+ elseif shell_name in (" powershell" , " pwsh" )
76+ _powershell_cmd (cmd)
77+ elseif shell_name == " busybox"
78+ command = ` $shell sh -c $(shell_escape_posixly (cmd)) `
79+ else
80+ command = ` $shell $cmd `
81+ end
82+ else
7083 if shell_name == " fish"
7184 shell_escape_cmd = " begin; $(shell_escape_posixly (cmd)) ; and true; end"
85+ elseif shell_name == " pwsh"
86+ _powershell_cmd (cmd)
7287 else
7388 shell_escape_cmd = " ($(shell_escape_posixly (cmd)) ) && true"
7489 end
75- cmd = ` $shell -c $shell_escape_cmd `
90+ command = ` $shell -c $shell_escape_cmd `
7691 end
77- run (ignorestatus (cmd ))
92+ run (ignorestatus (command ))
7893 end
7994 nothing
8095end
8196
97+ # process cmd's passed to CMD
98+ _CMD_execute (cmd) = Cmd (` $shell /c $(shell_escape_CMDly (shell_escape_winsomely (cmd))) ` , windows_verbatim= true )
99+
100+ function _powershell_execute (cmd)
101+ # process cmd's passed to powershell
102+ CommandType = nothing
103+ try
104+ CommandType = readchomp (` $shell -Command "Get-Command -- $(shell_escape_PWSH_cmdlet_ly (cmd. exec[1 ])) | Select-Object -ExpandProperty CommandType"` )
105+ catch
106+ end
107+ # TODO : while CommandType == "Alias"; CommandType = ...; end
108+ if CommandType == " Application"
109+ command = Cmd (` $shell -Command "& $(shell_escape_PWSHly (shell_escape_winsomely (cmd))) "` )
110+ else # handle Function and Cmdlet # TODO : what is the proper handling for the other types (ExternalScript, Script, Workflow, Configuration, and Filter)
111+ command = Cmd (` $shell -Command "& $(shell_escape_PWSH_cmdlet_ly (cmd)) "` )
112+ end
113+ return command
114+ end
115+
82116# deprecated function--preserved for DocTests.jl
83117function ip_matches_func (ip, func:: Symbol )
84118 for fr in StackTraces. lookup (ip)
0 commit comments