ls should use file names, not abs paths

main
Jordan Orelli 6 months ago
parent e71c3f89f7
commit af181b372c

@ -11,8 +11,13 @@ impl Call for Ls {
let cwd = env::current_dir()?;
let dir = fs::read_dir(&cwd)?;
for child in dir {
let child = child?;
_ = write!(ctx.stdout, "{}\n", child.path().display());
let child_path = child?.path();
let fname = child_path
.file_name()
.ok_or_else(|| ExecError::new("no file name"))?
.to_str()
.ok_or_else(|| ExecError::new("non-unicode file name"))?;
_ = write!(ctx.stdout, "{}\n", fname);
}
Ok(Value::None)
}

@ -126,6 +126,10 @@ impl ExecError {
pub fn type_error<S: Into<String>>(msg: S) -> Self {
Self::ValueTypeError(msg.into())
}
pub fn new<S: Into<String>>(msg: S) -> Self {
Self::Misc(msg.into())
}
}
impl Error {

Loading…
Cancel
Save