Shells in OCaml
1module Parameter = struct
2 type t =
3 | String of string
4 | Number of string
5 | Special of string
6 | Null (** Possible shell parameters *)
7end
8
9module type State = sig
10 type t
11 (** State for the shell and operating system that is carried from one
12 evaluation step to the next. *)
13
14 val cwd : t -> Fpath.t
15 (** The current working directory *)
16
17 val set_cwd : t -> Fpath.t -> t
18 (** Update the cwd *)
19
20 val expand : t -> [ `Tilde ] -> string
21 (** Expansions *)
22
23 val lookup : t -> param:string -> Ast.word_cst option
24 (** Parameter lookup. [None] means [unset]. *)
25
26 val update : t -> param:string -> Ast.word_cst -> t
27 (** Update the state with a new parameter mapping *)
28
29 val dump : t Fmt.t
30end
31
32type redirect =
33 | Redirect of int * Eio_unix.Fd.t * Eio_unix.Private.Fork_action.blocking
34 | Close of Eio_unix.Fd.t
35
36module type Exec = sig
37 type t
38 (** An executor for commands *)
39
40 type fork_action
41 (** A fork action is a piece of C-code to run inbetween the fork and the exec
42 *)
43
44 val exec :
45 ?fork_actions:fork_action list ->
46 ?fds:redirect list ->
47 ?stdin:_ Eio.Flow.source ->
48 ?stdout:_ Eio.Flow.sink ->
49 ?stderr:_ Eio.Flow.sink ->
50 ?env:(string * string) list ->
51 cwd:Eio.Fs.dir_ty Eio.Path.t ->
52 t ->
53 string list ->
54 unit Exit.t
55 (** Run a command in a child process *)
56end