Shells in OCaml
3
fork

Configure Feed

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

Add eval built-in

+66 -38
+19
src/lib/built_ins.ml
··· 49 49 | Command of { print_command : bool; args : string list } 50 50 | Alias 51 51 | Unalias 52 + | Eval of string list 52 53 53 54 (* Change Directory *) 54 55 module Cd = struct ··· 235 236 Cmd.v info term 236 237 end 237 238 239 + module Eval = struct 240 + open Cmdliner 241 + 242 + let args = 243 + let doc = "Arguments to concatenate, parse and execute." in 244 + Arg.(value & pos_all string [] & info [] ~docv:"ARGS" ~doc) 245 + 246 + let t = 247 + let make_eval args = Eval args in 248 + let term = Term.(const make_eval $ args) in 249 + let info = 250 + let doc = "Construct a command by concatenating arguments together." in 251 + Cmd.info "eval" ~doc 252 + in 253 + Cmd.v info term 254 + end 255 + 238 256 module Source = Make_dot (struct 239 257 let name = "source" 240 258 end) ··· 266 284 | "command" :: _ as cmd -> exec_cmd cmd Command.t 267 285 | "alias" :: _ -> Some (Ok Alias) 268 286 | "unalias" :: _ -> Some (Ok Unalias) 287 + | "eval" :: _ as cmd -> exec_cmd cmd Eval.t 269 288 | _ -> None
+1
src/lib/built_ins.mli
··· 26 26 | Command of { print_command : bool; args : string list } 27 27 | Alias 28 28 | Unalias 29 + | Eval of string list 29 30 30 31 val of_args : string list -> (t, string) result option 31 32 (** Parses a command-line to the built-ins, errors are returned if parsing. *)
+35
src/lib/eunix.ml
··· 48 48 Unix.close saved_stdout; 49 49 Unix.close saved_stderr) 50 50 fn 51 + 52 + let with_stdin_in_raw_mode fn = 53 + let saved_tio = Unix.tcgetattr Unix.stdin in 54 + let tio = 55 + { 56 + saved_tio with 57 + (* input modes *) 58 + c_ignpar = true; 59 + c_istrip = false; 60 + c_inlcr = false; 61 + c_igncr = false; 62 + c_ixon = false; 63 + (* c_ixany = false; *) 64 + (* c_iuclc = false; *) 65 + c_ixoff = false; 66 + (* output modes *) 67 + c_opost = true; 68 + (* control modes *) 69 + c_isig = false; 70 + c_icanon = false; 71 + c_echo = false; 72 + c_echoe = false; 73 + c_echok = false; 74 + c_echonl = false; 75 + (* c_iexten = false; *) 76 + 77 + (* special characters *) 78 + c_vmin = 1; 79 + c_vtime = 0; 80 + } 81 + in 82 + Unix.tcsetattr Unix.stdin TCSADRAIN tio; 83 + Fun.protect 84 + ~finally:(fun () -> Unix.tcsetattr Unix.stdin TCSADRAIN saved_tio) 85 + fn
+8 -1
src/lib/eval.ml
··· 436 436 match job with 437 437 | None -> Exit.zero ctx 438 438 | Some job -> 439 - if not async then J.await_exit ~pipefail:false job >|= fun () -> ctx 439 + if not async then begin 440 + J.await_exit ~pipefail:false job >|= fun () -> ctx 441 + end 440 442 else begin 441 443 Exit.zero { ctx with background_jobs = job :: ctx.background_jobs } 442 444 end ··· 890 892 Exit.zero ctx 891 893 | _ -> assert false) 892 894 | Alias | Unalias -> Exit.zero ctx (* Morbig handles this for us *) 895 + | Eval args -> 896 + let script = String.concat " " args in 897 + let ast = Ast.of_string script in 898 + let ctx, _ = run (Exit.zero ctx) ast in 899 + ctx 893 900 | Command _ -> 894 901 (* Handled separately *) 895 902 assert false
-35
src/lib/interactive.ml
··· 29 29 (Fpath.normalize @@ S.cwd state |> subst_tilde |> Fpath.to_string); 30 30 Format.flush_str_formatter () 31 31 32 - let _with_stdin_in_raw_mode fn = 33 - let saved_tio = Unix.tcgetattr Unix.stdin in 34 - let tio = 35 - { 36 - saved_tio with 37 - (* input modes *) 38 - c_ignpar = true; 39 - c_istrip = false; 40 - c_inlcr = false; 41 - c_igncr = false; 42 - c_ixon = false; 43 - (* c_ixany = false; *) 44 - (* c_iuclc = false; *) 45 - c_ixoff = false; 46 - (* output modes *) 47 - c_opost = true; 48 - (* control modes *) 49 - c_isig = false; 50 - c_icanon = false; 51 - c_echo = false; 52 - c_echoe = false; 53 - c_echok = false; 54 - c_echonl = false; 55 - (* c_iexten = false; *) 56 - 57 - (* special characters *) 58 - c_vmin = 1; 59 - c_vtime = 0; 60 - } 61 - in 62 - Unix.tcsetattr Unix.stdin TCSADRAIN tio; 63 - Fun.protect 64 - ~finally:(fun () -> Unix.tcsetattr Unix.stdin TCSADRAIN saved_tio) 65 - fn 66 - 67 32 let run ?(prompt = default_prompt) initial_ctx = 68 33 let rec loop (ctx : Eval.ctx Exit.t) = 69 34 Option.iter (Fmt.epr "%s%!")
+3 -2
src/lib/posix/exec.ml
··· 274 274 `Blocking ); 275 275 ]) 276 276 @ (if fd_exists 1 then [] 277 - else 277 + else begin 278 278 [ 279 279 ( 1, 280 280 write_of_fd ~mode stdout ~default:Eio_unix.Fd.stdout ~to_close, 281 281 `Blocking ); 282 - ]) 282 + ] 283 + end) 283 284 @ 284 285 if fd_exists 2 then [] 285 286 else