From 9d4fe4291377c1cc7fb3b5422f3d07e7f05ae749 Mon Sep 17 00:00:00 2001 From: GregPlowman Date: Tue, 12 Sep 2017 14:48:08 +1000 Subject: [PATCH 1/4] REPL shell mode for Windows REPL shell mode for Windows Documentation JULIA_SHELL environment variable Interacting with Julia docs - xref JULIA_SHELL Fix whitespace JULIA_SHELL doc Fix JULIA_SHELL cross-reference Address code review comments rebase fix --- base/client.jl | 24 ++++++++++++++++++++---- doc/src/manual/environment-variables.md | 7 +++---- stdlib/REPL/docs/src/index.md | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/base/client.jl b/base/client.jl index 73030847188ba..e73e04aa3d235 100644 --- a/base/client.jl +++ b/base/client.jl @@ -31,8 +31,11 @@ stackframe_lineinfo_color() = repl_color("JULIA_STACKFRAME_LINEINFO_COLOR", :bol stackframe_function_color() = repl_color("JULIA_STACKFRAME_FUNCTION_COLOR", :bold) function repl_cmd(cmd, out) - shell = shell_split(get(ENV, "JULIA_SHELL", get(ENV, "SHELL", "/bin/sh"))) + shell = shell_split(get(ENV, "JULIA_SHELL", Sys.iswindows() ? "cmd" : get(ENV, "SHELL", "/bin/sh"))) shell_name = Base.basename(shell[1]) + if Sys.iswindows() + shell_name = lowercase(splitext(shell_name)[1]) # canonicalize for comparisons below + end # Immediately expand all arguments, so that typing e.g. ~/bin/foo works. cmd.exec .= expanduser.(cmd.exec) @@ -66,15 +69,28 @@ function repl_cmd(cmd, out) ENV["OLDPWD"] = new_oldpwd println(out, pwd()) else - @static if !Sys.iswindows() + local command::Cmd + if Sys.iswindows() + if shell_name == "" + command = cmd + elseif shell_name == "cmd" + command = Cmd(`$shell /s /c $(string('"', cmd, '"'))`, windows_verbatim=true) + elseif shell_name == "powershell" + command = `$shell -Command $cmd` + elseif shell_name == "busybox" + command = `$shell sh -c $(shell_escape_posixly(cmd))` + else + command = `$shell $cmd` + end + else if shell_name == "fish" shell_escape_cmd = "begin; $(shell_escape_posixly(cmd)); and true; end" else shell_escape_cmd = "($(shell_escape_posixly(cmd))) && true" end - cmd = `$shell -c $shell_escape_cmd` + command = `$shell -c $shell_escape_cmd` end - run(ignorestatus(cmd)) + run(ignorestatus(command)) end nothing end diff --git a/doc/src/manual/environment-variables.md b/doc/src/manual/environment-variables.md index 0f84f78b0cb7d..d109a4c526e30 100644 --- a/doc/src/manual/environment-variables.md +++ b/doc/src/manual/environment-variables.md @@ -168,10 +168,9 @@ The absolute path of the shell with which Julia should execute external commands (via `Base.repl_cmd()`). Defaults to the environment variable `$SHELL`, and falls back to `/bin/sh` if `$SHELL` is unset. -!!! note - - On Windows, this environment variable is ignored, and external commands are - executed directly. +On Windows, `$JULIA_SHELL` can be set to `cmd`, `powershell`, `busybox` or `""`. +If set to `""` external commands are executed directly. Defaults to `cmd` if +`$JULIA_SHELL` is not set. ### `JULIA_EDITOR` diff --git a/stdlib/REPL/docs/src/index.md b/stdlib/REPL/docs/src/index.md index 052619358b037..5c103c3f726be 100644 --- a/stdlib/REPL/docs/src/index.md +++ b/stdlib/REPL/docs/src/index.md @@ -103,6 +103,7 @@ julia> ; # upon typing ;, the prompt changes (in place) to: shell> shell> echo hello hello ``` +See [`JULIA_SHELL`](@ref) in the Environment Variables section of the manual. ### Search modes From 2b646977cbfaa26016a8dbc69a38a0cd0d1acb4f Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 7 May 2019 17:08:57 -0400 Subject: [PATCH 2/4] rm missing cross-ref --- stdlib/REPL/docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/REPL/docs/src/index.md b/stdlib/REPL/docs/src/index.md index 5c103c3f726be..2d7bd15656ffc 100644 --- a/stdlib/REPL/docs/src/index.md +++ b/stdlib/REPL/docs/src/index.md @@ -103,7 +103,7 @@ julia> ; # upon typing ;, the prompt changes (in place) to: shell> shell> echo hello hello ``` -See [`JULIA_SHELL`](@ref) in the Environment Variables section of the manual. +See `JULIA_SHELL` in the Environment Variables section of the Julia manual. ### Search modes From 7a3fff1ea76b62b7681dbed5cc2dee43c64d9a51 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 8 May 2019 10:10:03 -0400 Subject: [PATCH 3/4] pwsh for powershell 6 --- base/client.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/client.jl b/base/client.jl index e73e04aa3d235..6156423442940 100644 --- a/base/client.jl +++ b/base/client.jl @@ -75,7 +75,7 @@ function repl_cmd(cmd, out) command = cmd elseif shell_name == "cmd" command = Cmd(`$shell /s /c $(string('"', cmd, '"'))`, windows_verbatim=true) - elseif shell_name == "powershell" + elseif shell_name == "powershell" || shell_name == "pwsh" command = `$shell -Command $cmd` elseif shell_name == "busybox" command = `$shell sh -c $(shell_escape_posixly(cmd))` From a2ae2e1ebab12c570f8f46ba44646a82d45d613b Mon Sep 17 00:00:00 2001 From: Mus Date: Mon, 30 Sep 2019 18:41:22 -0400 Subject: [PATCH 4/4] Repl shell mode fixes --- base/client.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/client.jl b/base/client.jl index 6156423442940..f239c73d55d1d 100644 --- a/base/client.jl +++ b/base/client.jl @@ -74,9 +74,9 @@ function repl_cmd(cmd, out) if shell_name == "" command = cmd elseif shell_name == "cmd" - command = Cmd(`$shell /s /c $(string('"', cmd, '"'))`, windows_verbatim=true) + command = Cmd(`$shell /s /c $(string('"', join(cmd.exec, ' '), '"'))`, windows_verbatim=true) elseif shell_name == "powershell" || shell_name == "pwsh" - command = `$shell -Command $cmd` + command = Cmd(`$shell -Command $(join(cmd.exec, ' '))`, windows_verbatim=true) elseif shell_name == "busybox" command = `$shell sh -c $(shell_escape_posixly(cmd))` else