aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
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(|| {