removed placeholder text in prompt
cd no longer panics if the given directory doesn't exist (wtf?)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use crate::{jobs::JobBldr, libsh::error::ShResult, parse::{NdRule, Node}, prelude::*, state::{self}};
|
||||
use crate::{jobs::JobBldr, libsh::error::{ShErr, ShErrKind, ShResult}, parse::{NdRule, Node}, prelude::*, state::{self}};
|
||||
|
||||
use super::setup_builtin;
|
||||
|
||||
pub fn cd(node: Node, job: &mut JobBldr) -> ShResult<()> {
|
||||
let span = node.get_span();
|
||||
let NdRule::Command { assignments: _, argv } = node.class else {
|
||||
unreachable!()
|
||||
};
|
||||
@@ -15,6 +16,26 @@ pub fn cd(node: Node, job: &mut JobBldr) -> ShResult<()> {
|
||||
PathBuf::from(env::var("HOME").unwrap())
|
||||
};
|
||||
|
||||
if !new_dir.exists() {
|
||||
return Err(
|
||||
ShErr::full(
|
||||
ShErrKind::ExecFail,
|
||||
format!("cd: No such file or directory '{}'",new_dir.display()),
|
||||
span,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if !new_dir.is_dir() {
|
||||
return Err(
|
||||
ShErr::full(
|
||||
ShErrKind::ExecFail,
|
||||
format!("cd: Not a directory '{}'",new_dir.display()),
|
||||
span,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
env::set_current_dir(new_dir).unwrap();
|
||||
let new_dir = env::current_dir().unwrap();
|
||||
env::set_var("PWD", new_dir);
|
||||
|
||||
Reference in New Issue
Block a user