Various improvements
This commit is contained in:
@@ -65,6 +65,9 @@ impl ExecCtx {
|
||||
clone.redirs = body_redirs;
|
||||
clone
|
||||
}
|
||||
pub fn redirs(&self) -> &Vec<Redir> {
|
||||
&self.redirs
|
||||
}
|
||||
pub fn sort_redirs(&self) -> (Vec<Redir>,Vec<Redir>) {
|
||||
let mut cond_redirs = vec![];
|
||||
let mut body_redirs = vec![];
|
||||
|
||||
@@ -75,7 +75,9 @@ pub fn enable_reaping() -> ShResult<()> {
|
||||
}
|
||||
|
||||
pub fn attach_tty(pgid: Pid) -> ShResult<()> {
|
||||
if !isatty(0).unwrap_or(false) || pgid == term_ctlr() {
|
||||
// If we aren't attached to a terminal, the pgid already controls it, or the process group does not exist
|
||||
// Then return ok
|
||||
if !isatty(0).unwrap_or(false) || pgid == term_ctlr() || killpg(pgid, None).is_err() {
|
||||
return Ok(())
|
||||
}
|
||||
log!(DEBUG, "Attaching tty to pgid: {}",pgid);
|
||||
|
||||
@@ -31,6 +31,24 @@ impl ShEnv {
|
||||
pub fn input_slice(&self, span: Rc<RefCell<Span>>) -> &str {
|
||||
&self.input_man.get_slice(span).unwrap_or_default()
|
||||
}
|
||||
pub fn source_file(&mut self, path: PathBuf) -> ShResult<()> {
|
||||
if path.is_file() {
|
||||
log!(DEBUG, "sourcing {}", path.to_str().unwrap());
|
||||
let mut file = std::fs::File::open(path)?;
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf)?;
|
||||
|
||||
exec_input(buf, self)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn source_rc(&mut self) -> ShResult<()> {
|
||||
log!(DEBUG, "sourcing rc");
|
||||
let path_raw = std::env::var("FERN_RC")?;
|
||||
let path = PathBuf::from(path_raw);
|
||||
self.source_file(path)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn expand_input(&mut self, new: &str, repl_span: Rc<RefCell<Span>>) -> Vec<Token> {
|
||||
log!(DEBUG,repl_span);
|
||||
if repl_span.borrow().expanded {
|
||||
@@ -131,17 +149,22 @@ impl ShEnv {
|
||||
&mut self.logic
|
||||
}
|
||||
pub fn save_io(&mut self) -> ShResult<()> {
|
||||
let ctx = self.ctx_mut();
|
||||
let stdin = ctx.masks().stdin().get_fd();
|
||||
let stdout = ctx.masks().stdout().get_fd();
|
||||
let stderr = ctx.masks().stderr().get_fd();
|
||||
if self.ctx_mut().saved_io().is_none() {
|
||||
let ctx = self.ctx_mut();
|
||||
let stdin = ctx.masks().stdin().get_fd();
|
||||
let stdout = ctx.masks().stdout().get_fd();
|
||||
let stderr = ctx.masks().stderr().get_fd();
|
||||
|
||||
let saved_in = dup(stdin)?;
|
||||
let saved_out = dup(stdout)?;
|
||||
let saved_err = dup(stderr)?;
|
||||
let saved_in = dup(stdin)?;
|
||||
log!(DEBUG, saved_in);
|
||||
let saved_out = dup(stdout)?;
|
||||
log!(DEBUG, saved_out);
|
||||
let saved_err = dup(stderr)?;
|
||||
log!(DEBUG, saved_err);
|
||||
|
||||
let saved_io = shellenv::exec_ctx::SavedIo::save(saved_in, saved_out, saved_err);
|
||||
*ctx.saved_io() = Some(saved_io);
|
||||
let saved_io = shellenv::exec_ctx::SavedIo::save(saved_in, saved_out, saved_err);
|
||||
*ctx.saved_io() = Some(saved_io);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn reset_io(&mut self) -> ShResult<()> {
|
||||
|
||||
@@ -94,6 +94,8 @@ impl VarTab {
|
||||
env::set_var("SHELL", pathbuf_to_string(std::env::current_exe()));
|
||||
env_vars.insert("FERN_HIST".into(),format!("{}/.fern_hist",home));
|
||||
env::set_var("FERN_HIST",format!("{}/.fern_hist",home));
|
||||
env_vars.insert("FERN_RC".into(),format!("{}/.fernrc",home));
|
||||
env::set_var("FERN_RC",format!("{}/.fernrc",home));
|
||||
|
||||
env_vars
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user