aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorLionel Flandrin2021-06-21 15:40:27 +0000
committerBenoƮt Cortier2021-06-22 23:20:51 +0000
commitb56174d7380fd299c4bcb8ded2f0127821dbe588 (patch)
treeeef17fb6bd39ee4cab0a715eeb4849cfd0af0597 /helix-term/src/commands.rs
parent866b32b5d7f997cf33cb9ec5c155348a58fc267b (diff)
Implement change_current_directory command
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c31c97fa..2f1db4b6 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1360,6 +1360,32 @@ mod cmd {
editor.set_status(editor.clipboard_provider.name().into());
}
+ fn change_current_directory(editor: &mut Editor, args: &[&str], _: PromptEvent) {
+ let dir = match args.first() {
+ Some(dir) => dir,
+ None => {
+ editor.set_error("target directory not provided".into());
+ return;
+ }
+ };
+
+ if let Err(e) = std::env::set_current_dir(dir) {
+ editor.set_error(format!(
+ "Couldn't change the current working directory: {:?}",
+ e
+ ));
+ return;
+ }
+
+ match std::env::current_dir() {
+ Ok(cwd) => editor.set_status(format!(
+ "Current working directory is now {}",
+ cwd.display()
+ )),
+ Err(e) => editor.set_error(format!("Couldn't get the new working directory: {}", e)),
+ }
+ }
+
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "quit",
@@ -1529,6 +1555,13 @@ mod cmd {
fun: show_clipboard_provider,
completer: None,
},
+ TypableCommand {
+ name: "change-current-directory",
+ alias: Some("cd"),
+ doc: "Change the current working directory (:cd <dir>).",
+ fun: change_current_directory,
+ completer: Some(completers::directory),
+ },
];
pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {