cd now tracks PWD
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
f902bd5473
commit
6351ac63d2
1 changed files with 20 additions and 3 deletions
|
|
@ -41,7 +41,7 @@ use {
|
|||
io::Result as IOResult,
|
||||
rc::Rc,
|
||||
fs::{
|
||||
File, OpenOptions
|
||||
File, OpenOptions, canonicalize,
|
||||
},
|
||||
path::Path,
|
||||
process::{
|
||||
|
|
@ -715,7 +715,7 @@ fn fg_callback(
|
|||
|
||||
const CD_DOCSTRING: &str =
|
||||
"Expects 1 argument (a string). Changes to a new directory";
|
||||
fn cd_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
||||
fn cd_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
||||
if let Ctr::String(ref dir) = *ast.car {
|
||||
let dirp = Path::new(dir);
|
||||
if let Err(s) = set_current_dir(dirp) {
|
||||
|
|
@ -723,7 +723,24 @@ fn cd_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
|||
("cd", s.to_string())
|
||||
.into()))
|
||||
} else {
|
||||
if let Ok(abs) = canonicalize(dirp) {
|
||||
syms.insert(
|
||||
String::from("PWD"),
|
||||
Symbol::from_ast(
|
||||
&String::from("PWD"),
|
||||
&String::from("current working directory"),
|
||||
&Seg::from_mono(Box::new(
|
||||
Ctr::String(abs.to_string_lossy().into()))),
|
||||
None,
|
||||
));
|
||||
|
||||
// Run configurable user function
|
||||
|
||||
Ok(Ctr::None)
|
||||
} else {
|
||||
Err(start_trace(
|
||||
("cd", "cannot make absolute path").into()))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(start_trace(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue