From f484c189d5fe3508978d9899c60804d2f2649c15 Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Fri, 6 Sep 2024 22:24:37 +0530 Subject: [PATCH] feat: support empty cd (#39) --- crates/deno_task_shell/src/shell/commands/cd.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/deno_task_shell/src/shell/commands/cd.rs b/crates/deno_task_shell/src/shell/commands/cd.rs index ea4f1ed..b4e1c3a 100644 --- a/crates/deno_task_shell/src/shell/commands/cd.rs +++ b/crates/deno_task_shell/src/shell/commands/cd.rs @@ -38,7 +38,13 @@ impl ShellCommand for CdCommand { } fn execute_cd(cwd: &Path, args: Vec) -> Result { - let path = parse_args(args)?; + // create a new vector to avoid modifying the original + let mut args = args; + if args.is_empty() { + // append `~` to args + args.push("~".to_string()); + } + let path = parse_args(args.clone())?; let new_dir = if path == "~" { dirs::home_dir() .ok_or_else(|| anyhow::anyhow!("Home directory not found"))?