Skip to content

Commit 16afe32

Browse files
authored
Address code review comments
1 parent 5771888 commit 16afe32

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

base/client.jl

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,42 +84,39 @@ answer_color() = text_colors[repl_color("JULIA_ANSWER_COLOR", default_color_answ
8484
stackframe_lineinfo_color() = repl_color("JULIA_STACKFRAME_LINEINFO_COLOR", :bold)
8585
stackframe_function_color() = repl_color("JULIA_STACKFRAME_FUNCTION_COLOR", :bold)
8686

87-
repl_cmd(line::AbstractString, out) = repl_cmd(Val(Sys.iswindows()), line, out)
88-
89-
function repl_cmd(iswindows::Val{false}, line::AbstractString, out)
90-
shell = shell_split(get(ENV, "JULIA_SHELL", get(ENV,"SHELL","/bin/sh")))
91-
shell_name = basename(shell[1])
92-
cmd = cmd_gen(eval(Main, shell_parse(line)[1]))
93-
if isempty(cmd)
94-
throw(ArgumentError("no cmd to execute"))
95-
elseif cmd[1] == "cd" && length(cmd) <= 2
96-
repl_cd(cmd, shell, out)
87+
function repl_cmd(line::AbstractString, out)
88+
if Sys.iswindows()
89+
shell = shell_split(get(ENV, "JULIA_SHELL", "cmd"))
90+
shell_name = isempty(shell) ? "" : lowercase(splitext(basename(shell[1]))[1])
9791
else
98-
run(ignorestatus(isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`))
92+
shell = shell_split(get(ENV, "JULIA_SHELL", get(ENV,"SHELL","/bin/sh")))
93+
shell_name = basename(shell[1])
9994
end
100-
nothing
101-
end
10295

103-
function repl_cmd(iswindows::Val{true}, line::AbstractString, out)
104-
shell = shell_split(get(ENV, "JULIA_SHELL", "cmd"))
105-
shell_name = isempty(shell) ? "" : lowercase(splitext(basename(shell[1]))[1])
10696
cmd = cmd_gen(eval(Main, shell_parse(line)[1]))
97+
10798
if isempty(cmd)
10899
throw(ArgumentError("no cmd to execute"))
109100
elseif cmd[1] == "cd" && length(cmd) <= 2
110101
repl_cd(cmd, shell, out)
111102
else
112-
interpolated_line = eval(Main, parse(string('"', escape_string(line), '"')))
113-
if shell_name == ""
114-
command = cmd
115-
elseif shell_name == "cmd"
116-
command = Cmd(`$shell /s /c $(string('"', interpolated_line, '"'))`, windows_verbatim=true)
117-
elseif shell_name == "powershell"
118-
command = `$shell -Command $interpolated_line`
119-
elseif shell_name == "busybox"
120-
command = `$shell sh -c $interpolated_line`
103+
local command::Cmd
104+
if Sys.iswindows()
105+
interpolated_line = eval(Main, parse(string('"', escape_string(line), '"')))::String
106+
if shell_name == ""
107+
command = cmd
108+
elseif shell_name == "cmd"
109+
command = Cmd(`$shell /s /c $(string('"', interpolated_line, '"'))`, windows_verbatim=true)
110+
elseif shell_name == "powershell"
111+
command = `$shell -Command $interpolated_line`
112+
elseif shell_name == "busybox"
113+
command = `$shell sh -c $interpolated_line`
114+
else
115+
command = `$shell $interpolated_line`
116+
end
121117
else
122-
command = `$shell $interpolated_line`
118+
ttyopt = STDIN isa TTY ? `-i` : ``
119+
command = `$shell $ttyopt -c "$(shell_wrap_true(shell_name, cmd))"`
123120
end
124121
run(ignorestatus(command))
125122
end

0 commit comments

Comments
 (0)