Skip to content

Commit daf5ff4

Browse files
author
Hugo Heuzard
committed
move bash trick next to bash call
1 parent a7afb96 commit daf5ff4

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/command.ml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ let search_in_path cmd =
145145

146146
(*** string_of_command_spec{,_with_calls *)
147147
let string_of_command_spec_with_calls call_with_tags call_with_target resolve_virtuals spec =
148-
let rec aux b spec =
148+
let rec aux spec =
149+
let b = Buffer.create 256 in
149150
let first = ref true in
150151
let put_space () =
151152
if !first then
@@ -166,21 +167,12 @@ let string_of_command_spec_with_calls call_with_tags call_with_target resolve_vi
166167
else (put_space (); Printf.bprintf b "<virtual %s>" (Shell.quote_filename_if_needed v))
167168
| S l -> List.iter do_spec l
168169
| T tags -> call_with_tags tags; do_spec (!tag_handler tags)
169-
| Quote s ->
170-
put_space ();
171-
let buf = Buffer.create 256 in
172-
aux buf s;
173-
put_filename (Buffer.contents buf)
170+
| Quote s -> put_space (); put_filename (aux s)
174171
in
175-
do_spec spec
172+
do_spec spec;
173+
Buffer.contents b
176174
in
177-
let b = Buffer.create 256 in
178-
(* The best way to prevent bash from switching to its windows-style
179-
* quote-handling is to prepend an empty string before the command name. *)
180-
if Sys.win32 then
181-
Buffer.add_string b "''";
182-
aux b spec;
183-
Buffer.contents b
175+
aux spec
184176

185177
let string_of_command_spec x = string_of_command_spec_with_calls ignore ignore false x
186178

src/my_std.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ let windows_shell = lazy begin
327327
end
328328

329329
let prepare_command_for_windows cmd =
330+
(* The best way to prevent bash from switching to its windows-style
331+
* quote-handling is to prepend an empty string before the command name. *)
332+
let cmd = "''" ^ cmd in
330333
Array.append (Lazy.force windows_shell) [|"-c"; cmd|]
331334

332335
let sys_command_win32 cmd =

0 commit comments

Comments
 (0)