From 565bfbba2562d84dbea63740a7e34a420082a016 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Thu, 5 Dec 2024 00:09:33 +0000 Subject: [PATCH] feat: `:cd` with no args changes to home directory (#12042) --- helix-term/src/commands/typed.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 4e3946a3..e6ec8b57 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -9,6 +9,7 @@ use super::*; use helix_core::fuzzy::fuzzy_match; use helix_core::indent::MAX_INDENT; use helix_core::{line_ending, shellwords::Shellwords}; +use helix_stdx::path::home_dir; use helix_view::document::{read_to_string, DEFAULT_LANGUAGE_NAME}; use helix_view::editor::{CloseError, ConfigEvent}; use serde_json::Value; @@ -1089,11 +1090,14 @@ fn change_current_directory( return Ok(()); } - let dir = args - .first() - .context("target directory not provided")? - .as_ref(); - let dir = helix_stdx::path::expand_tilde(Path::new(dir)); + let dir = match args.first() { + Some(input_path) => { + helix_stdx::path::expand_tilde(Path::new(input_path.as_ref()).to_owned()) + .deref() + .to_path_buf() + } + None => home_dir()?.as_path().to_owned(), + }; helix_stdx::env::set_current_working_dir(dir)?;