Shells in OCaml
3
fork

Configure Feed

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

at arith 81 lines 2.4 kB view raw
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 : ?export:bool -> t -> param:string -> Ast.word_cst -> t 27 (** Update the state with a new parameter mapping and whether or not it should 28 exported to the environment (default false). *) 29 30 val remove : param:string -> t -> bool * t 31 (** [remove ~param t] removes [param] from [t] if it exists. [bool] is [true] 32 if a removal took place. *) 33 34 val exports : t -> (string * Ast.word_cst) list 35 (** All of the variables that must be exported to the environment *) 36 37 val dump : t Fmt.t 38end 39 40type redirect = 41 | Redirect of int * Eio_unix.Fd.t * Eio_unix.Private.Fork_action.blocking 42 | Close of Eio_unix.Fd.t 43 44type exec_mode = 45 | Switched of Eio.Switch.t 46 | Async 47 (** How to execute a process. This mainly controls what happens at the end 48 of the running a script or some commands. When a process is 49 "switched", we use the same semantics as Eio, we sigkill the process 50 and cleanup. If the process is complete Async then we do not wait. 51 This allows us to exit before some of our child processes, which is a 52 requirement for implementing the semantics of a shell! *) 53 54module type Exec = sig 55 type t 56 (** An executor for commands *) 57 58 type process 59 60 val signal : process -> int -> unit 61 val pid : process -> int 62 63 val exec : 64 ?delay_reap:unit Eio.Promise.t -> 65 ?fork_actions:Eio_unix__.Fork_action.t list -> 66 ?fds:redirect list -> 67 ?stdin:_ Eio.Flow.source -> 68 ?stdout:_ Eio.Flow.sink -> 69 ?stderr:_ Eio.Flow.sink -> 70 ?env:(string * string) list -> 71 mode:exec_mode -> 72 pgid:int -> 73 cwd:Eio.Fs.dir_ty Eio.Path.t -> 74 executable:string -> 75 t -> 76 string list -> 77 (process, int * [ `Not_found ]) result 78 (** Run a command in a child process *) 79 80 val await : process -> unit Exit.t 81end