diff options
author | Yomain | 2023-07-11 17:51:04 +0000 |
---|---|---|
committer | GitHub | 2023-07-11 17:51:04 +0000 |
commit | 8afc0282f28e73cf78d1bd7b11d78fd853ae2036 (patch) | |
tree | 6742e141f051d352ebe7017f15805613670864b9 /helix-term/src/commands/typed.rs | |
parent | 1adb19464f002926e1042027b41acef4c81585f6 (diff) |
Fix crash when cwd is deleted (#7185)
Diffstat (limited to 'helix-term/src/commands/typed.rs')
-rw-r--r-- | helix-term/src/commands/typed.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 94cc33f0..dfc71dfd 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1093,14 +1093,11 @@ fn change_current_directory( .as_ref(), ); - if let Err(e) = std::env::set_current_dir(dir) { - bail!("Couldn't change the current working directory: {}", e); - } + helix_loader::set_current_working_dir(dir)?; - let cwd = std::env::current_dir().context("Couldn't get the new working directory")?; cx.editor.set_status(format!( "Current working directory is now {}", - cwd.display() + helix_loader::current_working_dir().display() )); Ok(()) } @@ -1114,9 +1111,14 @@ fn show_current_directory( return Ok(()); } - let cwd = std::env::current_dir().context("Couldn't get the new working directory")?; - cx.editor - .set_status(format!("Current working directory is {}", cwd.display())); + let cwd = helix_loader::current_working_dir(); + let message = format!("Current working directory is {}", cwd.display()); + + if cwd.exists() { + cx.editor.set_status(message); + } else { + cx.editor.set_error(format!("{} (deleted)", message)); + } Ok(()) } |