Struct brush_core::Shell

source ·
pub struct Shell {
Show 18 fields pub traps: TrapHandlerConfig, pub open_files: OpenFiles, pub working_dir: PathBuf, pub env: ShellEnvironment, pub funcs: FunctionEnv, pub options: RuntimeOptions, pub jobs: JobManager, pub aliases: HashMap<String, String>, pub last_exit_status: u8, pub depth: usize, pub positional_parameters: Vec<String>, pub shell_name: Option<String>, pub script_call_stack: VecDeque<String>, pub function_call_stack: VecDeque<FunctionCall>, pub directory_stack: Vec<PathBuf>, pub current_line_number: u32, pub completion_config: Config, pub builtins: HashMap<String, Registration>,
}
Expand description

Represents an instance of a shell.

Fields§

§traps: TrapHandlerConfig

Trap handler configuration for the shell.

§open_files: OpenFiles

Manages files opened and accessible via redirection operators.

§working_dir: PathBuf

The current working directory.

§env: ShellEnvironment

The shell environment, containing shell variables.

§funcs: FunctionEnv

Shell function definitions.

§options: RuntimeOptions

Runtime shell options.

§jobs: JobManager

State of managed jobs.

§aliases: HashMap<String, String>

Shell aliases.

§last_exit_status: u8

The status of the last completed command.

§depth: usize

Clone depth from the original ancestor shell.

§positional_parameters: Vec<String>

Positional parameters ($1 and beyond)

§shell_name: Option<String>

Shell name

§script_call_stack: VecDeque<String>

Script call stack.

§function_call_stack: VecDeque<FunctionCall>

Function call stack.

§directory_stack: Vec<PathBuf>

Directory stack used by pushd et al.

§current_line_number: u32

Current line number being processed.

§completion_config: Config

Completion configuration.

§builtins: HashMap<String, Registration>

Shell built-in commands.

Implementations§

source§

impl Shell

source

pub async fn new(options: &CreateOptions) -> Result<Shell, Error>

Returns a new shell instance created with the given options.

§Arguments
  • options - The options to use when creating the shell.
source

pub async fn source<S: AsRef<str>>( &mut self, path: &Path, args: &[S], params: &ExecutionParameters, ) -> Result<ExecutionResult, Error>

Source the given file as a shell script, returning the execution result.

§Arguments
  • path - The path to the file to source.
  • args - The arguments to pass to the script as positional parameters.
  • params - Execution parameters.
source

pub async fn source_file<S: AsRef<str>>( &mut self, file: &File, source_info: &SourceInfo, args: &[S], params: &ExecutionParameters, ) -> Result<ExecutionResult, Error>

Source the given file as a shell script, returning the execution result.

§Arguments
  • file - The file to source.
  • source_info - Information about the source of the script.
  • args - The arguments to pass to the script as positional parameters.
  • params - Execution parameters.
source

pub async fn invoke_function( &mut self, name: &str, args: &[&str], ) -> Result<u8, Error>

Invokes a function defined in this shell, returning the resulting exit status.

§Arguments
  • name - The name of the function to invoke.
  • args - The arguments to pass to the function.
source

pub async fn run_string( &mut self, command: String, params: &ExecutionParameters, ) -> Result<ExecutionResult, Error>

Executes the given string as a shell program, returning the resulting exit status.

§Arguments
  • command - The command to execute.
  • params - Execution parameters.
source

pub fn parse_string(&self, s: String) -> Result<Program, ParseError>

Parses the given string as a shell program, returning the resulting Abstract Syntax Tree for the program.

§Arguments
  • s - The string to parse as a program.
source

pub async fn basic_expand_string<S: AsRef<str>>( &mut self, s: S, ) -> Result<String, Error>

Applies basic shell expansion to the provided string.

§Arguments
  • s - The string to expand.
source

pub async fn full_expand_and_split_string<S: AsRef<str>>( &mut self, s: S, ) -> Result<Vec<String>, Error>

Applies full shell expansion and field splitting to the provided string; returns a sequence of fields.

§Arguments
  • s - The string to expand and split.
source

pub fn default_exec_params(&self) -> ExecutionParameters

Returns the default execution parameters for this shell.

source

pub async fn run_script<S: AsRef<str>>( &mut self, script_path: &Path, args: &[S], ) -> Result<ExecutionResult, Error>

Executes the given script file, returning the resulting exit status.

§Arguments
  • script_path - The path to the script file to execute.
  • args - The arguments to pass to the script as positional parameters.
source

pub async fn run_program( &mut self, program: Program, params: &ExecutionParameters, ) -> Result<ExecutionResult, Error>

Executes the given parsed shell program, returning the resulting exit status.

§Arguments
  • program - The program to execute.
  • params - Execution parameters.
source

pub async fn compose_prompt(&mut self) -> Result<String, Error>

Composes the shell’s prompt, applying all appropriate expansions.

source

pub fn last_result(&self) -> u8

Returns the exit status of the last command executed in this shell.

source

pub fn get_history_file_path(&self) -> Option<PathBuf>

Returns the path to the history file used by the shell, if one is set.

source

pub async fn get_completions( &mut self, input: &str, position: usize, ) -> Result<Completions, Error>

Generates command completions for the shell.

§Arguments
  • input - The input string to generate completions for.
  • position - The position in the input string to generate completions at.
source

pub fn stdout(&self) -> OpenFile

Returns a value that can be used to write to the shell’s currently configured standard output stream using write! at al.

source

pub fn stderr(&self) -> OpenFile

Returns a value that can be used to write to the shell’s currently configured standard error stream using write! et al.

source

pub fn check_for_completed_jobs(&mut self) -> Result<(), Error>

Checks for completed jobs in the shell, reporting any changes found.

Trait Implementations§

source§

impl Clone for Shell

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Shell

§

impl RefUnwindSafe for Shell

§

impl Send for Shell

§

impl Sync for Shell

§

impl Unpin for Shell

§

impl UnwindSafe for Shell

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<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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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