···66let strf = Printf.sprintf
77let error_to_failure = function Ok v -> v | Error e -> failwith e
8899+let quote_tool tool =
1010+ (* Can be replaced by Filename.quote_command once we drop OCaml < 4.10 *)
1111+ Filename.quote @@
1212+ if Sys.win32 then String.map (function '/' -> '\\' | c -> c) tool else tool
1313+914let find_sub ?(start = 0) ~sub s =
1015 (* naive algorithm, worst case O(length sub * length s) *)
1116 let len_sub = String.length sub in
···2934 let err_cmd exit cmd =
3035 raise (Sys_error (strf "exited with %d: %s\n" exit cmd))
3136 in
3232- let quote_cmd = if Sys.win32 then fun cmd -> strf "\"%s\"" cmd else Fun.id in
3337 let run_cmd args =
3438 let cmd = String.concat " " (List.map Filename.quote args) in
3535- let exit = Sys.command (quote_cmd cmd) in
3939+ let exit = Sys.command cmd in
3640 if exit = 0 then () else err_cmd exit cmd
3741 in
3842 let parent = Filename.dirname dir in
···165169 | [] -> []
166170 in
167171 let exec =
168168- strf "%s --__complete %s --__complete=" (Filename.quote tool) cmd
172172+ strf "%s --__complete %s --__complete=" (quote_tool tool) cmd
169173 in
170174 let comps = exec_stdout exec |> error_to_failure in
171175 let comps = String.split_on_char '\n' comps in
···186190 with Failure e -> Error e
187191188192let get_tool_command_man tool ~name cmd =
189189- let tool = Filename.quote tool in
193193+ let tool = quote_tool tool in
190194 let exec = if cmd = "" then tool else String.concat " " [tool; cmd] in
191195 let man_basename =
192196 let exec = if cmd = "" then name else String.concat " " [name; cmd] in