Skip to content

Commit

Permalink
Revert to replacement in parse_args
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Sep 6, 2024
1 parent aaa108d commit f704f29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
15 changes: 3 additions & 12 deletions crates/deno_task_shell/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,19 +684,10 @@ fn parse_word(pair: Pair<Rule>) -> Result<Word> {
match part.as_rule() {
Rule::EXIT_STATUS => parts.push(WordPart::Variable("?".to_string())),
Rule::UNQUOTED_CHAR => {
let char = part.as_str().chars().next().unwrap();
let text = if char == '~' {
dirs::home_dir()
.map(|p| p.to_string_lossy().into_owned())
.unwrap_or_else(|| "~".to_string())
} else {
char.to_string()
};

if let Some(WordPart::Text(ref mut existing_text)) = parts.last_mut() {
existing_text.push_str(&text);
if let Some(WordPart::Text(ref mut text)) = parts.last_mut() {
text.push(part.as_str().chars().next().unwrap());
} else {
parts.push(WordPart::Text(text));
parts.push(WordPart::Text(part.as_str().to_string()));
}
}
Rule::UNQUOTED_ESCAPE_CHAR => {
Expand Down
13 changes: 9 additions & 4 deletions crates/deno_task_shell/src/shell/commands/cd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ fn execute_cd(cwd: &Path, args: Vec<String>) -> Result<PathBuf> {
// create a new vector to avoid modifying the original
let mut args = args;
if args.is_empty() {
// append homedir to args
let home_dir = dirs::home_dir().unwrap();
args.push(home_dir.to_string_lossy().to_string());
// append '~' to args
args.push("~".to_string());
}
let path = parse_args(args.clone())?;
let new_dir = cwd.join(&path);
Expand All @@ -64,7 +63,13 @@ fn parse_args(args: Vec<String>) -> Result<String> {
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()?,
}
Expand Down

0 comments on commit f704f29

Please sign in to comment.