String.concat " " (List.map Parse.shquote (ch_last (List.fold_left common_prefix p ps) cmd))
let complete_file cmd f =
- let dir_files dir =
- let d = Unix.opendir dir in
- let rec gen_list () =
- try
- let f = Unix.readdir d in
- f :: gen_list ()
- with End_of_file -> []
- in
- let files = gen_list () in
- Unix.closedir d;
- files
- in
- let files =
- match String.rindex_opt f '/' with
- | Some 0 -> List.map (( ^ ) "/") (dir_files "/")
- | Some i -> List.map (( ^ ) (String.sub f 0 (i + 1))) (dir_files (String.sub f 0 i))
- | None -> dir_files "."
- in
- real_complete cmd (List.map (fun f -> if (Unix.stat f).st_kind = S_DIR then f ^ "/" else f) files)
+ try
+ let dir_files dir =
+ let d = Unix.opendir dir in
+ let rec gen_list () =
+ try
+ let f = Unix.readdir d in
+ f :: gen_list ()
+ with End_of_file -> []
+ in
+ let files = gen_list () in
+ Unix.closedir d;
+ files
+ in
+ let files =
+ match String.rindex_opt f '/' with
+ | Some 0 -> List.map (( ^ ) "/") (dir_files "/")
+ | Some i -> List.map (( ^ ) (String.sub f 0 (i + 1))) (dir_files (String.sub f 0 i))
+ | None -> dir_files "."
+ in
+ real_complete cmd (List.map (fun f -> if (Unix.stat f).st_kind = S_DIR then f ^ "/" else f) files)
+ with Unix.Unix_error _ -> real_complete cmd []
let autocomplete cmd =
match try Parse.shlex cmd with Parse.NonTerminatedString -> Parse.shlex (cmd ^ "'") with