1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Defines state traits for the shell.
use std::{
borrow::Cow,
collections::HashMap,
path::{Path, PathBuf},
};
use crate::{
completion, env::ShellEnvironment, jobs, openfiles, options::RuntimeOptions, pathcache,
shell::KeyBindingsHelper,
};
/// A dyn-safe trait for constrained access to shell state.
pub trait ShellState {
/// Returns whether or not this shell is a subshell.
fn is_subshell(&self) -> bool;
/// Returns the last "SECONDS" captured time.
fn last_stopwatch_time(&self) -> std::time::SystemTime;
/// Returns the last "SECONDS" offset requested.
fn last_stopwatch_offset(&self) -> u32;
/// Returns the shell environment containing variables.
fn env(&self) -> &ShellEnvironment;
/// Returns a mutable reference to the shell environment.
fn env_mut(&mut self) -> &mut ShellEnvironment;
/// Returns the shell's runtime options.
fn options(&self) -> &RuntimeOptions;
/// Returns a mutable reference to the shell's runtime options.
fn options_mut(&mut self) -> &mut RuntimeOptions;
/// Returns the shell's aliases.
fn aliases(&self) -> &HashMap<String, String>;
/// Returns a mutable reference to the shell's aliases.
fn aliases_mut(&mut self) -> &mut HashMap<String, String>;
/// Returns the shell's job manager.
fn jobs(&self) -> &jobs::JobManager;
/// Returns a mutable reference to the shell's job manager.
fn jobs_mut(&mut self) -> &mut jobs::JobManager;
/// Returns the shell's trap handler configuration.
fn traps(&self) -> &crate::traps::TrapHandlerConfig;
/// Returns a mutable reference to the shell's trap handler configuration.
fn traps_mut(&mut self) -> &mut crate::traps::TrapHandlerConfig;
/// Returns the shell's directory stack.
fn directory_stack(&self) -> &[PathBuf];
/// Returns a mutable reference to the shell's directory stack.
fn directory_stack_mut(&mut self) -> &mut Vec<PathBuf>;
/// Returns the statuses of commands in the last pipeline.
fn last_pipeline_statuses(&self) -> &[u8];
/// Returns a mutable reference to the statuses of commands in the last pipeline.
fn last_pipeline_statuses_mut(&mut self) -> &mut Vec<u8>;
/// Returns the shell's program location cache.
fn program_location_cache(&self) -> &pathcache::PathCache;
/// Returns a mutable reference to the shell's program location cache.
fn program_location_cache_mut(&mut self) -> &mut pathcache::PathCache;
/// Returns the shell's completion configuration.
fn completion_config(&self) -> &completion::Config;
/// Returns a mutable reference to the shell's completion configuration.
fn completion_config_mut(&mut self) -> &mut completion::Config;
/// Returns the shell's open files.
fn open_files(&self) -> &openfiles::OpenFiles;
/// Returns a mutable reference to the shell's open files.
fn open_files_mut(&mut self) -> &mut openfiles::OpenFiles;
/// Returns the *current* name of the shell ($0).
fn current_shell_name(&self) -> Option<Cow<'_, str>>;
/// Returns the current subshell depth; 0 is returned if this shell is not a subshell.
fn depth(&self) -> usize;
/// Returns the call stack for the shell.
fn call_stack(&self) -> &crate::callstack::CallStack;
/// Returns the shell's history, if it exists.
fn history(&self) -> Option<&crate::history::History>;
/// Returns a mutable reference to the shell's history, if it exists.
fn history_mut(&mut self) -> Option<&mut crate::history::History>;
/// Returns the shell's official version string (if available).
fn version(&self) -> Option<&str>;
/// Returns the exit status of the last command executed in this shell.
fn last_exit_status(&self) -> u8;
/// Updates the last exit status.
fn set_last_exit_status(&mut self, status: u8);
/// Returns the key bindings helper for the shell.
fn key_bindings(&self) -> Option<&KeyBindingsHelper>;
/// Sets the key bindings helper for the shell.
fn set_key_bindings(&mut self, key_bindings: Option<KeyBindingsHelper>);
/// Returns the shell's current working directory.
fn working_dir(&self) -> &Path;
/// Returns a mutable reference to the shell's current working directory.
/// This is only accessible within the crate.
fn working_dir_mut(&mut self) -> &mut PathBuf;
/// Returns the product display name for this shell.
fn product_display_str(&self) -> Option<&str>;
}