Skip to content

Commit

Permalink
Added support for cd ~ (#37)
Browse files Browse the repository at this point in the history
* Added support for cd ~

* run fmt
  • Loading branch information
prsabahrami authored Sep 6, 2024
1 parent 6aac187 commit 0a38e5d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/deno_task_shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/deno_task_shell/src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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 | "_")+ }
Expand Down
7 changes: 6 additions & 1 deletion crates/deno_task_shell/src/shell/commands/cd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ impl ShellCommand for CdCommand {

fn execute_cd(cwd: &Path, args: Vec<String>) -> Result<PathBuf> {
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
Expand Down

0 comments on commit 0a38e5d

Please sign in to comment.