feat: in-line shell evaluation

This commit is contained in:
iff 2023-08-04 00:52:49 +02:00
parent 8ae71443d6
commit b5f2f139e4
4 changed files with 19 additions and 3 deletions

View file

@ -60,7 +60,7 @@ fn gen_match_rules(rules: Vec<Rule>) -> TokenStream {
let suggests = x let suggests = x
.suggest .suggest
.iter() .iter()
.map(|x| x.to_lowercase()) .map(|x| x.to_string())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
(pattern, suggests) (pattern, suggests)
}) })

View file

@ -188,7 +188,13 @@ pub fn shell_tag(suggest: &mut String, replace_list: &mut Vec<TokenStream2>, cmd
if suggest.contains(&command) { if suggest.contains(&command) {
*suggest = suggest.replace(&command, &tag(tag_name, replace_tag)); *suggest = suggest.replace(&command, &tag(tag_name, replace_tag));
replace_list.push(rtag(tag_name, replace_tag, command));
let split = command.split_once(',').unwrap();
let argument = split.1.trim_end_matches(')').trim();
let argument = format!("\"{}\"", argument);
let function = format!("{}, {}).join(\"\")", split.0, argument);
// let function = format!("\"{}, {}\"", split.0, split.1);
replace_list.push(rtag(tag_name, replace_tag, function));
replace_tag += 1; replace_tag += 1;
} }
} }

View file

@ -75,3 +75,14 @@ suggest = [
git checkout {{typo[2]({{shell(git branch)}})}} git checkout {{typo[2]({{shell(git branch)}})}}
''' '''
] ]
[[match_err]]
pattern = [
"current branch test has no upstream branch"
]
suggest = [
'''
#[cmd_contains(push)]
git push --set-upstream origin {{shell(git rev-parse --abbrev-ref HEAD)}}
'''
]

View file

@ -75,7 +75,6 @@ fn eval_shell_command(shell: &str, command: &str) -> Vec<String> {
.expect("failed to execute process"); .expect("failed to execute process");
let output = String::from_utf8_lossy(&output.stdout); let output = String::from_utf8_lossy(&output.stdout);
let split_output = output.split('\n').collect::<Vec<&str>>(); let split_output = output.split('\n').collect::<Vec<&str>>();
println!("{:?}", split_output);
split_output split_output
.iter() .iter()
.map(|s| s.trim().to_string()) .map(|s| s.trim().to_string())