Skip to content

Commit

Permalink
helix-term: cd to the parent of the current document when provided no…
Browse files Browse the repository at this point in the history
… arguments
  • Loading branch information
cole-h committed Aug 23, 2022
1 parent e4c9d40 commit 3f3487a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,12 +911,21 @@ fn change_current_directory(
return Ok(());
}

let dir = helix_core::path::expand_tilde(
args.first()
.context("target directory not provided")?
.as_ref()
.as_ref(),
);
let dir = match args.first() {
Some(dir) => helix_core::path::expand_tilde(dir.as_ref().as_ref()),
None => {
let (_, doc) = current_ref!(cx.editor);
match doc.path() {
Some(path) => path
.parent()
.map(ToOwned::to_owned)
.context("Couldn't get parent of current document")?,
None => {
bail!("Current document has no path");
}
}
}
};

if let Err(e) = std::env::set_current_dir(dir) {
bail!("Couldn't change the current working directory: {}", e);
Expand Down

0 comments on commit 3f3487a

Please sign in to comment.