| x :: t -> x :: ch_last v t
| [] -> assert false
+ let common_prefix s s' =
+ let rec aux i m =
+ if i < 0 then String.sub s 0 m else if s.[i] = s'.[i] then aux (i - 1) m else aux (i - 1) i
+ in
+ let len = min (String.length s) (String.length s') in
+ aux (len - 1) len
+
let real_complete cmd completions =
let last = last cmd in
match List.filter (String.starts_with ~prefix:last) completions with
Printf.fprintf stderr "No completions !\n%!";
String.concat " " (List.map Parse.shquote cmd)
| [possibility] -> String.concat " " (List.map Parse.shquote (ch_last possibility cmd)) ^ " "
- | possibilities ->
+ | p :: ps ->
Printf.fprintf stderr "Completions:\n%!";
- List.iter (Printf.fprintf stderr "\t%s\n%!") possibilities;
- String.concat " " (List.map Parse.shquote cmd)
+ List.iter (Printf.fprintf stderr "\t%s\n%!") (p :: ps);
+ 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 =