From 1e06f2e85dc91171059e3ad6fc446de45d2766ed Mon Sep 17 00:00:00 2001
From: prsabahrami
Date: Fri, 6 Sep 2024 11:13:03 -0400
Subject: [PATCH 1/2] Added support for cd ~
---
Cargo.lock | 1 +
crates/deno_task_shell/Cargo.toml | 1 +
crates/deno_task_shell/src/grammar.pest | 2 +-
crates/deno_task_shell/src/shell/commands/cd.rs | 6 +++++-
4 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 58bc594..d02fc67 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -260,6 +260,7 @@ name = "deno_task_shell"
version = "0.17.0"
dependencies = [
"anyhow",
+ "dirs",
"futures",
"glob",
"os_pipe",
diff --git a/crates/deno_task_shell/Cargo.toml b/crates/deno_task_shell/Cargo.toml
index 5830b1f..4d192a0 100644
--- a/crates/deno_task_shell/Cargo.toml
+++ b/crates/deno_task_shell/Cargo.toml
@@ -26,6 +26,7 @@ serde = { version = "1", features = ["derive"], optional = true }
thiserror = "1.0.58"
pest = "2.6.0"
pest_derive = "2.6.0"
+dirs = "5.0.1"
[dev-dependencies]
parking_lot = "0.12.1"
diff --git a/crates/deno_task_shell/src/grammar.pest b/crates/deno_task_shell/src/grammar.pest
index 0c7e8b3..600cedd 100644
--- a/crates/deno_task_shell/src/grammar.pest
+++ b/crates/deno_task_shell/src/grammar.pest
@@ -31,7 +31,7 @@ QUOTED_PENDING_WORD = ${ (
UNQUOTED_ESCAPE_CHAR = ${ ("\\" ~ "$" | "$" ~ !"(" ~ !VARIABLE) | "\\" ~ (" " | "`" | "\"" | "(" | ")")* }
QUOTED_ESCAPE_CHAR = ${ "\\" ~ "$" | "$" ~ !"(" ~ !VARIABLE | "\\" ~ ("`" | "\"" | "(" | ")" | "'")* }
-UNQUOTED_CHAR = ${ ("\\" ~ " ") | !("~" | "(" | ")" | "{" | "}" | "<" | ">" | "|" | "&" | ";" | "\"" | "'" | "$") ~ ANY }
+UNQUOTED_CHAR = ${ ("\\" ~ " ") | !("(" | ")" | "{" | "}" | "<" | ">" | "|" | "&" | ";" | "\"" | "'" | "$") ~ ANY }
QUOTED_CHAR = ${ !"\"" ~ ANY }
VARIABLE = ${ (ASCII_ALPHANUMERIC | "_")+ }
diff --git a/crates/deno_task_shell/src/shell/commands/cd.rs b/crates/deno_task_shell/src/shell/commands/cd.rs
index 54ae007..4831a2c 100644
--- a/crates/deno_task_shell/src/shell/commands/cd.rs
+++ b/crates/deno_task_shell/src/shell/commands/cd.rs
@@ -39,7 +39,11 @@ impl ShellCommand for CdCommand {
fn execute_cd(cwd: &Path, args: Vec) -> Result {
let path = parse_args(args)?;
- let new_dir = cwd.join(&path);
+ let new_dir = if path == "~" {
+ dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Home directory not found"))?
+ } else {
+ cwd.join(&path)
+ };
let new_dir = match new_dir.parse_dot() {
Ok(path) => path.to_path_buf(),
// fallback to canonicalize path just in case
From e0f1d4ba103df85aa8260fb8058bf3f37a681e12 Mon Sep 17 00:00:00 2001
From: prsabahrami
Date: Fri, 6 Sep 2024 11:14:23 -0400
Subject: [PATCH 2/2] run fmt
---
crates/deno_task_shell/src/shell/commands/cd.rs | 3 ++-
1 file changed, 2 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 4831a2c..ea4f1ed 100644
--- a/crates/deno_task_shell/src/shell/commands/cd.rs
+++ b/crates/deno_task_shell/src/shell/commands/cd.rs
@@ -40,7 +40,8 @@ impl ShellCommand for CdCommand {
fn execute_cd(cwd: &Path, args: Vec) -> Result {
let path = parse_args(args)?;
let new_dir = if path == "~" {
- dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Home directory not found"))?
+ dirs::home_dir()
+ .ok_or_else(|| anyhow::anyhow!("Home directory not found"))?
} else {
cwd.join(&path)
};