Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cb00fd3

Browse files
committedDec 14, 2021
Fix path globbing
1 parent 4224f0c commit cb00fd3

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
 

‎src/parsers/lexer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ pub fn cmd_to_tokens(line: &str) -> Result<Vec<CmdToTokensReturn>> {
188188
token.clear();
189189
Normal
190190
}
191+
191192
(DollarVariable, c) if !valid_name_check(c) => {
192193
result.push((CmdTokens::Variable, token.trim().to_string(), true));
193194
token.clear();
194-
token.push(c);
195+
token.push(c); // Todo: See if variable
195196
Normal
196197
}
197198
(DollarVariable, _) => {

‎src/parsers/parser.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use super::errors::*;
24
use super::*;
35
use crate::utils;
@@ -13,6 +15,7 @@ pub fn parse_cmd(token: String, status: i32) -> Result<Vec<(tokens::ParseCmdToke
1315
let mut is_definition: bool = false;
1416
// Todo: part should give boolean if escaped/quoted or not, for wildcards, variables and ~
1517
for part in lexer::cmd_to_tokens(&token)?.iter().peekable() {
18+
println!("{:?}", part);
1619
before_token = match part.0 {
1720
tokens::CmdTokens::Pipe => {
1821
if before_token.is_none() || before_token == Some(tokens::CmdTokens::Pipe) {
@@ -60,12 +63,20 @@ pub fn parse_cmd(token: String, status: i32) -> Result<Vec<(tokens::ParseCmdToke
6063
} else {
6164
// Glob paths. ex ./*.md
6265
if let Ok(globs) = glob(&val) {
63-
let mut has_entry = false;
64-
for entry in globs.flatten() {
65-
has_entry = true;
66-
result_part.push(entry.display().to_string());
67-
}
68-
if !has_entry {
66+
let globs_vec: Vec<PathBuf> = globs.flatten().collect();
67+
68+
// If there is none
69+
if globs_vec.len() > 0 && globs_vec[0].display().to_string() != "." {
70+
for entry in globs_vec {
71+
let entry_string = entry.display().to_string();
72+
if !entry_string.starts_with("/") {
73+
result_part
74+
.push(format!("./{}", entry.display().to_string()));
75+
} else {
76+
result_part.push(entry.display().to_string());
77+
}
78+
}
79+
} else {
6980
result_part.push(val);
7081
}
7182
}

‎src/shell.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl Shell {
8686
} else {
8787
Stdio::inherit()
8888
};
89+
// If application does not print something with a new line at end, it would get overwritten by the shell
8990
match Command::new(command)
9091
.args(args.clone())
9192
.stdin(stdin)

0 commit comments

Comments
 (0)
Please sign in to comment.