Skip to main content

ShellCore

Struct ShellCore 

Source
pub struct ShellCore<'os> { /* private fields */ }
Expand description

The shared session state and execution machinery.

The core owns the session’s working directory, environment, and the CommandRuntime that actually launches commands. External commands are resolved through PATH and the runtime’s executable bindings; builtins are dispatched through the ShellDialect the shell was created with.

Implementations§

Source§

impl<'os> ShellCore<'os>

Source

pub fn new( os: &'os UnixOs, credentials: Credentials, dialect: ShellDialect, ) -> Result<Self, OsError>

Creates a core for a session, executing in the given shell dialect.

Source

pub fn cwd(&self) -> &VirtualPath

The current working directory.

Source

pub fn set_cwd(&mut self, cwd: VirtualPath)

Sets the working directory (used by non-interactive interpreter invocations, which start in the caller’s directory).

Source

pub fn environment(&self) -> &Environment

The shell environment.

Source

pub fn environment_mut(&mut self) -> &mut Environment

The shell environment, mutable.

Source

pub fn credentials(&self) -> &Credentials

The credentials this shell runs as.

Source

pub fn os(&self) -> &'os UnixOs

The OS this shell runs on.

Source

pub fn history(&self) -> &[String]

Returns the command history.

Source

pub fn record_history(&mut self, line: &str)

Records one completed command line.

The interactive application calls this once per executed line — the whole of a multi-line construct, not its continuation chunks — so history shows exactly what the user typed. Internal re-execution (rc sourcing, alias expansion, function bodies) never records.

Source

pub fn aliases(&self) -> &BTreeMap<String, String>

Returns the aliases.

Source

pub fn aliases_mut(&mut self) -> &mut BTreeMap<String, String>

The aliases, mutable.

Source

pub fn functions_mut(&mut self) -> &mut BTreeMap<String, String>

The functions, mutable.

Source

pub fn set_terminal_size(&mut self, rows: u16, cols: u16)

Reports the terminal size, exported as COLUMNS/LINES.

Source

pub fn source_startup_files(&mut self)

Sources the dialect’s startup files (system-wide then per-user), so aliases, functions, and variables from real rc files exist in every session. Missing files are simply skipped, as real shells do.

Source

pub fn install_shell_bindings(&mut self)

Binds the interpreter behaviors onto the standard shell programs so scripts execute through the same implementation as interactive commands: /bin/sh and /bin/bash speak the Bash dialect, /bin/zsh speaks the Zsh dialect, wherever those programs exist on this system. Shebang interpreters resolve through these bindings too.

Source

pub fn execute( &mut self, line: &str, stdin: &mut dyn Input, stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

Executes a line of shell input.

Source

pub fn execute_with_terminal( &mut self, line: &str, stdin: &mut dyn Input, stdout: &mut dyn Output, stderr: &mut dyn Output, terminal: Option<&mut dyn Terminal>, ) -> ExitStatus

Executes a line, optionally handing a terminal to a command that asks for one.

Source

pub fn request_exit(&mut self, status_argument: Option<&str>) -> ExitStatus

Records an exit [N] request and returns its status.

The status argument follows real shells: a missing or non-numeric argument means success; an out-of-range value wraps modulo 256 (exit 300 exits with status 44, like bash).

Source

pub fn take_exit_request(&mut self) -> Option<ExitStatus>

Takes a pending exit request, if any.

The application calls this after executing a line: when it returns Some, the session is over and the carried status is the process exit code.

Source

pub fn resolve_with_hash( &mut self, name: &str, ) -> Result<CommandResolution, OsError>

Resolves a command name, consulting the hash table first.

Source

pub fn resolve_external_path(&mut self, name: &str) -> Option<String>

Resolves an external command to its filesystem path, without hashing.

Source

pub fn resolve_external_paths(&mut self, name: &str) -> Vec<String>

Every filesystem location that resolves the name as an executable, in PATH order (the Zsh where builtin prints them all).

Source

pub fn executable_path(&self, path: &VirtualPath) -> Option<VirtualPath>

The absolute path of an existing executable, if any.

Source

pub fn display_path(&self, path: &VirtualPath) -> String

The home-relative display form of a path (/Users/rey → ~).

Source

pub fn is_directory(&self, path: &VirtualPath) -> bool

Whether path is an existing directory.

Source

pub fn expand_glob(&self, pattern: &str) -> Vec<String>

Expands a glob (*, ?) in an argument via the virtual filesystem.

Source

pub fn resolve_path(&self, argument: &str) -> Result<VirtualPath, OsError>

Resolves a path argument: absolute paths are used directly, relative paths are joined onto the working directory, honoring . and .. components. An empty argument is an error, like the real tools.

Source

pub fn write_redirect( &mut self, path_str: &str, bytes: &[u8], append: bool, ) -> Result<(), OsError>

Writes captured output to a redirection target (creating it when needed), or discards it for the null device.

Source

pub fn execute_script( &mut self, script_path: &str, stdin: &mut dyn Input, stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

Executes a script file line by line.

Source

pub fn cd_to( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The cd builtin: changes the working directory, with cd - returning to the previous directory (OLDPWD).

Source

pub fn pwd_of(&self, stdout: &mut dyn Output) -> ExitStatus

The pwd builtin.

Source

pub fn list_jobs(&mut self, stdout: &mut dyn Output) -> ExitStatus

The jobs builtin: lists this session’s background jobs with their virtual-time state. A pending job shows Running until the clock reaches its completion; then it shows Done.

Source

pub fn foreground_job( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The fg builtin: brings a background job to the foreground. Waiting for a pending job is advancing the virtual clock to its completion time; the invocation’s exit status is the job’s.

Source

pub fn background_job( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The bg builtin: re-reports a background job as running in the background. Execution is sequential, so there is nothing to resume: a pending job is already running, and a finished one stays finished.

Source

pub fn wait_for_jobs( &mut self, argv: &[String], stderr: &mut dyn Output, ) -> ExitStatus

The wait builtin: advances the virtual clock until background jobs complete. With no arguments, waits for all pending ones; otherwise waits for each %spec/pid argument. Returns the last waited job’s exit status.

Source

pub fn builtin_echo( &self, argv: &[String], stdout: &mut dyn Output, ) -> ExitStatus

The echo builtin, shared by Bash and Zsh: -n suppresses the newline, -e/-E enable and disable escape processing. The default escape behavior is the dialect’s (Bash off, Zsh on).

Source

pub fn builtin_export( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The export builtin, shared by Bash and Zsh: assignments set the environment; with no arguments the listing prefix is the dialect’s (declare -x in Bash, export in Zsh).

Source

pub fn builtin_history(&self, stdout: &mut dyn Output) -> ExitStatus

The history builtin, identical in Bash and Zsh: prints the numbered command history.

Source

pub fn builtin_alias( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The alias builtin, shared by Bash and Zsh: definitions set aliases; with no arguments the listing prefix is the dialect’s (alias in Bash, nothing in Zsh).

Source

pub fn builtin_unalias( &mut self, argv: &[String], stderr: &mut dyn Output, ) -> ExitStatus

The unalias builtin, identical in Bash and Zsh.

Source

pub fn resolve_name( &mut self, name: &str, is_builtin: fn(&str) -> bool, ) -> NameResolution

How a name resolves for the type/which/where/whence family: one shared precedence walk (alias → function → builtin → PATH), with the phrasing owned by each shell’s reporter.

Source

pub fn hash_table( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The hash builtin: manages the command hash table.

Source

pub fn print_dirs(&self, stdout: &mut dyn Output) -> ExitStatus

The dirs builtin: prints the directory stack, current directory first, with ~ for the home directory.

Source

pub fn push_directory( &mut self, argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The pushd builtin: pushes the current directory onto the stack and changes to the argument.

Source

pub fn pop_directory( &mut self, _argv: &[String], stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The popd builtin: pops the top of the directory stack and changes into it.

Source

pub fn unset_names( &mut self, argv: &[String], stderr: &mut dyn Output, ) -> ExitStatus

The unset builtin: removes variables, or functions with -f.

Source

pub fn source_file( &mut self, argv: &[String], stdin: &mut dyn Input, stdout: &mut dyn Output, stderr: &mut dyn Output, ) -> ExitStatus

The source/. builtin: reads the named file and executes it in the current shell.

Source

pub fn null_command(&self) -> ExitStatus

The : null command: does nothing and succeeds.

Source

pub fn clear_screen(&self, stdout: &mut dyn Output) -> ExitStatus

The clear builtin: emits the terminal clear sequence (including the scrollback erase, like zsh’s clear on macOS).

Source§

impl<'os> ShellCore<'os>

Source

pub fn expand_word(&mut self, raw: &str) -> String

Expands a word with quoting semantics, discarding the glob marker.

Source

pub fn expand_word_fields(&mut self, raw: &str) -> Vec<String>

Expands a word and splits it into fields on the default IFS characters (space, tab, newline), as unquoted expansions are in real shells: v="a b"; ls $v passes two arguments. Characters from quoted sections never split.

An empty expansion yields no fields; the caller decides whether an empty argument is meaningful.

Source

pub fn expand_word_with_glob(&mut self, raw: &str) -> (String, bool)

Expands a word with quoting semantics, reporting whether it contains unquoted glob characters.

Auto Trait Implementations§

§

impl<'os> !RefUnwindSafe for ShellCore<'os>

§

impl<'os> !UnwindSafe for ShellCore<'os>

§

impl<'os> Freeze for ShellCore<'os>

§

impl<'os> Send for ShellCore<'os>

§

impl<'os> Sync for ShellCore<'os>

§

impl<'os> Unpin for ShellCore<'os>

§

impl<'os> UnsafeUnpin for ShellCore<'os>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more