removed placeholder text in prompt

cd no longer panics if the given directory doesn't exist (wtf?)
This commit is contained in:
2025-05-29 01:29:25 -04:00
parent 4465a4f6f6
commit 220f636ebd
6 changed files with 37 additions and 7 deletions

View File

@@ -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);

View File

@@ -15,7 +15,7 @@ pub fn source(node: Node, job: &mut JobBldr) -> ShResult<()> {
return Err(
ShErr::full(
ShErrKind::ExecFail,
"source: File not found",
format!("source: File '{}' not found",path.display()),
span
)
);
@@ -24,7 +24,7 @@ pub fn source(node: Node, job: &mut JobBldr) -> ShResult<()> {
return Err(
ShErr::full(
ShErrKind::ExecFail,
"source: Given path is not a file",
format!("source: Given path '{}' is not a file",path.display()),
span
)
);