Unified execution context for defbash functions in both builtins and interop.
Manages process-dictionary-based I/O context with support for nesting
(e.g., eval calling builtins). Provides stdout/stderr writing, stdin reading,
state access, and delta-based state updates.
I/O Functions
write/1- Write raw data to stdoutwrite_stderr/1- Write raw data to stderrputs/1- Write to stdout with trailing newlineerror/1- Write to stderr with trailing newline
Stdin
gets/0- Read a line from stdinread/1- Read from stdin (:all,:line, or byte count)stream/1- Get stdin as a lazy stream
Output Streams
stream/2- Stream an enumerable to stdout or stderr
State
get_state/0- Get the current session stateupdate_state/1- Accumulate state update deltas
Summary
Functions
Delete the current context and restore previous (for interop cleanup).
Write message to stderr with trailing newline.
Get the current session state.
Get accumulated state updates from the current context.
Read a line from stdin.
Write message to stdout with trailing newline.
Write to stdout or stderr.
Read from stdin.
Get stdin as a lazy stream.
Stream an enumerable to stdout or stderr.
Request state updates to be applied after execution completes.
Write raw data to stdout (no newline added).
Write raw data to stderr (no newline added).
Types
Functions
@spec delete_context() :: :ok
Delete the current context and restore previous (for interop cleanup).
@spec error(String.t()) :: :ok
Write message to stderr with trailing newline.
@spec get_state() :: map()
Get the current session state.
@spec get_state_updates() :: map()
Get accumulated state updates from the current context.
Used by interop's execute_with_context to retrieve deltas without
going through finalize/1.
Read a line from stdin.
Returns {:ok, line}, :eof, or {:error, reason}.
@spec puts(String.t()) :: :ok
Write message to stdout with trailing newline.
@spec puts(:stdout | :stderr, String.t()) :: :ok
Write to stdout or stderr.
When called with a stream target and message:
puts(:stdout, message)- Write to stdoutputs(:stderr, message)- Write to stderr
@spec read(:all | :line | non_neg_integer()) :: {:ok, String.t()} | :eof | {:error, term()}
Read from stdin.
Modes:
:all- Read all remaining input:line- Read a single line (same asgets/0)n(integer) - Read n bytes
@spec stream(:stdin) :: Enumerable.t()
Get stdin as a lazy stream.
Returns an empty stream if no stdin is available.
@spec stream(:stdout | :stderr, Enumerable.t()) :: :ok
Stream an enumerable to stdout or stderr.
Each element is converted to a string and written immediately.
Request state updates to be applied after execution completes.
Accumulates a delta map of update keys.
For more details on settings variables, see Bash.Variable. By default, a string key
and string value will default to an exported variable.
Example
update_state(
working_dir: "/new/path",
variables: %{"PWD" => "/new/path"}
)
@spec write(iodata()) :: :ok
Write raw data to stdout (no newline added).
@spec write_stderr(iodata()) :: :ok
Write raw data to stderr (no newline added).