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,
|
io::Result as IOResult,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
fs::{
|
fs::{
|
||||||
File, OpenOptions
|
File, OpenOptions, canonicalize,
|
||||||
},
|
},
|
||||||
path::Path,
|
path::Path,
|
||||||
process::{
|
process::{
|
||||||
|
|
@ -715,7 +715,7 @@ fn fg_callback(
|
||||||
|
|
||||||
const CD_DOCSTRING: &str =
|
const CD_DOCSTRING: &str =
|
||||||
"Expects 1 argument (a string). Changes to a new directory";
|
"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 {
|
if let Ctr::String(ref dir) = *ast.car {
|
||||||
let dirp = Path::new(dir);
|
let dirp = Path::new(dir);
|
||||||
if let Err(s) = set_current_dir(dirp) {
|
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())
|
("cd", s.to_string())
|
||||||
.into()))
|
.into()))
|
||||||
} else {
|
} else {
|
||||||
Ok(Ctr::None)
|
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 {
|
} else {
|
||||||
Err(start_trace(
|
Err(start_trace(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue