Skip to content

Commit 1373a70

Browse files
committed
add windows support for shell REPL mode
1 parent aa1bf48 commit 1373a70

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

base/client.jl

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ end
6565
function prepare_shell_command(::ShellSpecification{false,:nu}, raw_string)
6666
return `nu -c $raw_string`
6767
end
68+
function prepare_shell_command(::ShellSpecification{true,:cmd}, cmd)
69+
return Cmd(`cmd /s /c $(string('"', cmd, '"'))`; windows_verbatim=true)
70+
end
71+
function prepare_shell_command(::ShellSpecification{true,:powershell}, cmd)
72+
return `powershell -Command $cmd`
73+
end
74+
function prepare_shell_command(::ShellSpecification{true,:pwsh}, cmd)
75+
return `pwsh -Command $cmd`
76+
end
77+
function prepare_shell_command(::ShellSpecification{true,:busybox}, cmd)
78+
return `busybox sh -c $(shell_escape_posixly(cmd))`
79+
end
80+
6881

6982
"""
7083
needs_cmd(::ShellSpecification) -> Bool
@@ -83,13 +96,19 @@ Determines if a command is a `cd` command. Overload this for
8396
shells that have a different syntax for `cd`.
8497
"""
8598
is_cd_cmd(::ShellSpecification, cmd::Cmd) = cmd.exec[1] == "cd"
86-
is_cd_cmd(::ShellSpecification, cmd::String) = false
99+
is_cd_cmd(::ShellSpecification{true,:cmd}, cmd::Cmd) = cmd.exec[1] in ("cd", "chdir")
100+
is_cd_cmd(::ShellSpecification{true,:powershell}, cmd::Cmd) = cmd.exec[1] ("Set-Location", "cd", "sl", "chdir")
101+
is_cd_cmd(::ShellSpecification{true,:pwsh}, cmd::Cmd) = cmd.exec[1] ("Set-Location", "cd", "sl", "chdir")
102+
is_cd_cmd(::ShellSpecification{true,:busybox}, cmd::Cmd) = cmd.exec[1] == "cd"
103+
is_cd_cmd(::ShellSpecification, cmd::String) = false # Safe default
87104
is_cd_cmd(::ShellSpecification{false,:nu}, raw_string::String) = startswith(strip(raw_string), "cd")
88105

89106
function pre_repl_cmd(raw_string, parsed, out)
90-
shell = shell_split(get(ENV, "JULIA_SHELL", get(ENV, "SHELL", "/bin/sh")))
91-
shell_name = Base.basename(shell[1])
92-
shell_spec = ShellSpecification{@static(Sys.iswindows() ? true : false),Symbol(shell_name)}()
107+
is_windows = Sys.iswindows()
108+
shell_path = shell_split(get(ENV, "JULIA_SHELL", is_windows ? "cmd" : get(ENV, "SHELL", "/bin/sh")))
109+
shell_name = Base.basename(shell_path[1])
110+
normalized_shell_name = is_windows ? lowercase(splitext(shell_name)[1]) : shell_name
111+
shell_spec = ShellSpecification{is_windows,Symbol(normalized_shell_name)}()
93112
if needs_cmd(shell_spec)
94113
cmd = Base.cmd_gen(parsed)
95114
return repl_cmd(shell_spec, cmd, parsed, out)

0 commit comments

Comments
 (0)