tangled
alpha
login
or
join now
ryan.freumh.org
/
merry
forked from
patrick.sirref.org/merry
0
fork
atom
Shells in OCaml
0
fork
atom
overview
issues
pulls
pipelines
Built-in redirection
Patrick Ferris
1 month ago
8933bf5f
972d29c1
+10
-4
3 changed files
expand all
collapse all
unified
split
src
lib
eunix.ml
eval.ml
test
simple.t
+1
-1
src/lib/eunix.ml
···
48
48
(function
49
49
| Types.Redirect (i, fd, _) ->
50
50
Eio_unix.Fd.use_exn "with_redirections" fd @@ fun fd ->
51
51
-
Unix.dup2 fd (fd_of_int i)
51
51
+
if (Obj.magic fd : int) <> i then Unix.dup2 fd (fd_of_int i)
52
52
| Types.Close fd -> Eio_unix.Fd.close fd)
53
53
rdrs;
54
54
Fun.protect
+8
-2
src/lib/eval.ml
···
428
428
let ctx =
429
429
handle_built_in ~rdrs ~stdout:some_write ctx bi
430
430
in
431
431
+
let ctx =
432
432
+
ctx >|= fun ctx -> clear_local_state ctx
433
433
+
in
431
434
close_stdout ~is_global some_write;
432
435
let built_in = ctx >|= fun _ -> () in
433
436
let job = handle_job job (`Built_in built_in) in
···
479
482
loop ctx job some_read rest)))))
480
483
| Some (Ok bi) ->
481
484
let ctx = handle_built_in ~rdrs ~stdout:some_write ctx bi in
485
485
+
let ctx = ctx >|= fun ctx -> clear_local_state ctx in
482
486
close_stdout ~is_global some_write;
483
487
let built_in = ctx >|= fun _ -> () in
484
488
let job = handle_job job (`Built_in built_in) in
···
989
993
(ctx, []) swc
990
994
991
995
and handle_built_in ~rdrs ~(stdout : Eio_unix.sink_ty Eio.Flow.sink)
992
992
-
(ctx : ctx) = function
996
996
+
(ctx : ctx) v =
997
997
+
let rdrs = ctx.rdrs @ rdrs in
998
998
+
Eunix.with_redirections rdrs @@ fun () ->
999
999
+
match v with
993
1000
| Built_ins.Cd { path } ->
994
1001
let cwd = S.cwd ctx.state in
995
1002
let+ state =
···
1009
1016
{ ctx with state }
1010
1017
| Pwd ->
1011
1018
let () =
1012
1012
-
Eunix.with_redirections rdrs @@ fun () ->
1013
1019
Eio.Flow.copy_string
1014
1020
(Fmt.str "%a\n%!" Fpath.pp (S.cwd ctx.state))
1015
1021
stdout
+1
-1
test/simple.t
···
179
179
180
180
Redirection of fds
181
181
182
182
-
$ msh -c "echo hello 3>out.txt >&3"
182
182
+
$ msh -c "echo hello 789>out.txt >&789"
183
183
$ cat out.txt
184
184
hello
185
185