Simplify change_current_directory and remove extra allocs

This commit is contained in:
Michael Davis 2024-12-05 18:50:31 -05:00
parent 93deb1f6ae
commit 28953ef40f
No known key found for this signature in database

View File

@ -1090,18 +1090,14 @@ fn change_current_directory(
return Ok(()); return Ok(());
} }
let dir = match args.first() { let dir = match args.first().map(AsRef::as_ref) {
Some(Cow::Borrowed("-")) => cx Some("-") => cx
.editor .editor
.last_cwd .last_cwd
.clone() .clone()
.ok_or(anyhow!("No previous working directory"))?, .ok_or(anyhow!("No previous working directory"))?,
Some(input_path) => { Some(input_path) => helix_stdx::path::expand_tilde(Path::new(input_path)).to_path_buf(),
helix_stdx::path::expand_tilde(Path::new(input_path.as_ref()).to_owned()) None => home_dir()?,
.deref()
.to_path_buf()
}
None => home_dir()?.as_path().to_owned(),
}; };
cx.editor.last_cwd = helix_stdx::env::set_current_working_dir(dir)?; cx.editor.last_cwd = helix_stdx::env::set_current_working_dir(dir)?;