Shells in OCaml
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Command fixes

The command built-in should allow normal shell built-ins to just work.

+54 -35
+50 -35
src/lib/eval.ml
··· 374 374 in 375 375 loop saved_ctx job (pgid, some_read) rest 376 376 | None -> ( 377 - let exec_and_args = 378 - if is_command then begin 379 - match command_args with 380 - | [] -> assert false 381 - | x :: xs -> ( 382 - Eunix.with_redirections rdrs @@ fun () -> 383 - match resolve_program ~update:false ctx x with 384 - | _, None -> Exit.nonzero ("", []) 1 385 - | _, Some prog -> 386 - if print_command then 387 - Exit.zero ("echo", [ prog ]) 388 - else Exit.zero (x, xs)) 389 - end 390 - else Exit.zero (executable, args_as_strings) 391 - in 392 - match exec_and_args with 393 - | Exit.Nonzero _ as v -> 394 - let job = 395 - handle_job ~pgid job (`Built_in (v >|= fun _ -> ())) 377 + match Built_ins.of_args command_args with 378 + | Some (Error _) -> 379 + ( ctx, 380 + handle_job ~pgid job (`Built_in (Exit.nonzero () 1)) 381 + ) 382 + | Some (Ok bi) -> 383 + let ctx = 384 + handle_built_in ~rdrs ~stdout:some_write ctx bi 385 + in 386 + close_stdout ~is_global some_write; 387 + let built_in = ctx >|= fun _ -> () in 388 + let job = handle_job ~pgid job (`Built_in built_in) in 389 + loop (Exit.value ctx) job (pgid, some_read) rest 390 + | _ -> ( 391 + let exec_and_args = 392 + if is_command then begin 393 + match command_args with 394 + | [] -> assert false 395 + | x :: xs -> ( 396 + Eunix.with_redirections rdrs @@ fun () -> 397 + match resolve_program ~update:false ctx x with 398 + | _, None -> Exit.nonzero ("", []) 1 399 + | _, Some prog -> 400 + if print_command then 401 + Exit.zero ("echo", [ prog ]) 402 + else Exit.zero (x, xs)) 403 + end 404 + else Exit.zero (executable, args_as_strings) 396 405 in 397 - loop ctx job (pgid, some_read) rest 398 - | Exit.Zero (executable, args) -> ( 399 - match stdout_of_previous with 400 - | None -> 401 - let ctx, job = 402 - exec_process ctx job ~fds:rdrs 403 - ~stdout:some_write ~pgid executable args 406 + match exec_and_args with 407 + | Exit.Nonzero _ as v -> 408 + let job = 409 + handle_job ~pgid job 410 + (`Built_in (v >|= fun _ -> ())) 404 411 in 405 - close_stdout ~is_global some_write; 406 412 loop ctx job (pgid, some_read) rest 407 - | Some stdout -> 408 - let ctx, job = 409 - exec_process ctx job ~fds:rdrs ~stdin:stdout 410 - ~stdout:some_write ~pgid executable 411 - args_as_strings 412 - in 413 - close_stdout ~is_global some_write; 414 - loop ctx job (pgid, some_read) rest)))) 413 + | Exit.Zero (executable, args) -> ( 414 + match stdout_of_previous with 415 + | None -> 416 + let ctx, job = 417 + exec_process ctx job ~fds:rdrs 418 + ~stdout:some_write ~pgid executable args 419 + in 420 + close_stdout ~is_global some_write; 421 + loop ctx job (pgid, some_read) rest 422 + | Some stdout -> 423 + let ctx, job = 424 + exec_process ctx job ~fds:rdrs ~stdin:stdout 425 + ~stdout:some_write ~pgid executable 426 + args_as_strings 427 + in 428 + close_stdout ~is_global some_write; 429 + loop ctx job (pgid, some_read) rest))))) 415 430 | Some (Ok bi) -> 416 431 let ctx = handle_built_in ~rdrs ~stdout:some_write ctx bi in 417 432 close_stdout ~is_global some_write;
+4
test/built_ins.t
··· 184 184 $ msh -c "command -v skjdlksjdlkwjdlkw" 185 185 [1] 186 186 187 + Command should also still allow shell built-ins to run. 188 + 189 + $ msh -c "command pwd | xargs -- basename" 190 + 187 191 8. Alias 188 192 189 193 This is mostly handled by Morbig, but we have had to do some fixes...