65
65
function prepare_shell_command (:: ShellSpecification{false,:nu} , raw_string)
66
66
return ` nu -c $raw_string `
67
67
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
+
68
81
69
82
"""
70
83
needs_cmd(::ShellSpecification) -> Bool
@@ -83,13 +96,19 @@ Determines if a command is a `cd` command. Overload this for
83
96
shells that have a different syntax for `cd`.
84
97
"""
85
98
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
87
104
is_cd_cmd (:: ShellSpecification{false,:nu} , raw_string:: String ) = startswith (strip (raw_string), " cd" )
88
105
89
106
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)} ()
93
112
if needs_cmd (shell_spec)
94
113
cmd = Base. cmd_gen (parsed)
95
114
return repl_cmd (shell_spec, cmd, parsed, out)
0 commit comments