aboutsummaryrefslogtreecommitdiffhomepage
path: root/share
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-08-18 16:55:01 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-08-19 18:06:24 -0700
commite849beabbab31c83ac57693cb0a7ac1e58f8cfd5 (patch)
treefa8872516ac378bd32ef3be5844100bc64cf4c1b /share
parent2979d3bf169f51fb2ba218897994745754f830f9 (diff)
Initial work towards various IO cleanups with an eye to fixing https://github.com/fish-shell/fish-shell/issues/110
Diffstat (limited to 'share')
-rw-r--r--share/functions/eval.fish13
1 files changed, 13 insertions, 0 deletions
diff --git a/share/functions/eval.fish b/share/functions/eval.fish
index 19f20731..939b17c9 100644
--- a/share/functions/eval.fish
+++ b/share/functions/eval.fish
@@ -19,6 +19,19 @@ function eval -S -d "Evaluate parameters as a command"
status --job-control full
end
+ # rfish: To eval 'foo', we construct a block "begin ; foo; end <&3 3<&-"
+ # The 'eval2_inner' is a param to 'begin' itself; I believe it does nothing.
+ # Note the redirections are also within the quotes.
+ #
+ # We then pipe this to 'source 3<&0' which dup2's 3 to stdin.
+ #
+ # You might expect that the dup2(3, stdin) should overwrite stdin,
+ # and therefore prevent 'source' from reading the piped-in block. This doesn't happen
+ # because when you pipe to a builtin, we don't overwrite stdin with the read end
+ # of the block; instead we set a separate fd in a variable 'builtin_stdin', which is
+ # what it reads from. So builtins are magic in that, in pipes, their stdin
+ # is not fd 0.
+
echo "begin; $argv "\n" ;end eval2_inner <&3 3<&-" | source 3<&0
set -l res $status