From 8e7f28e5f3fee5eb33ba3e4c8b6f4dcc7cd3f541 Mon Sep 17 00:00:00 2001
From: prsabahrami
Date: Fri, 6 Sep 2024 17:55:18 -0400
Subject: [PATCH] Replace ~ with homedir
---
crates/deno_task_shell/src/shell/commands/cd.rs | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/crates/deno_task_shell/src/shell/commands/cd.rs b/crates/deno_task_shell/src/shell/commands/cd.rs
index b4e1c3a..ac3c60f 100644
--- a/crates/deno_task_shell/src/shell/commands/cd.rs
+++ b/crates/deno_task_shell/src/shell/commands/cd.rs
@@ -41,16 +41,11 @@ fn execute_cd(cwd: &Path, args: Vec) -> Result {
// create a new vector to avoid modifying the original
let mut args = args;
if args.is_empty() {
- // append `~` to args
+ // append homedir 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"))?
- } else {
- cwd.join(&path)
- };
+ let new_dir = cwd.join(&path);
let new_dir = match new_dir.parse_dot() {
Ok(path) => path.to_path_buf(),
// fallback to canonicalize path just in case
@@ -68,7 +63,13 @@ fn parse_args(args: Vec) -> Result {
for arg in args {
match arg {
ArgKind::Arg(arg) => {
- paths.push(arg);
+ if arg.contains('~') {
+ let home_dir = dirs::home_dir().unwrap();
+ let arg = arg.replacen("~", home_dir.to_string_lossy().as_ref(), 1);
+ paths.push(arg);
+ } else {
+ paths.push(arg.to_string());
+ }
}
_ => arg.bail_unsupported()?,
}