@@ -7,6 +7,7 @@ use std::process::Command;
77use directories:: BaseDirs ;
88use regex:: Regex ;
99use serde:: { Serialize , Deserialize } ;
10+ use std:: collections:: HashSet ;
1011
1112use skim:: * ;
1213
@@ -57,17 +58,27 @@ impl Runner {
5758 /// process choose time arguments, and do corresponding string replacements
5859 pub fn get_args ( & mut self ) {
5960 let re = Regex :: new ( r"\{\s*(.*?)\s*\}" ) . unwrap ( ) ;
60- let handlebar_matches = re. find_iter ( & self . cmd ) ;
61+ let handlebar_matches = re. captures_iter ( & self . cmd ) ;
6162
62- let keys: Vec < _ > = handlebar_matches. map ( |m| m. as_str ( ) ) . collect ( ) ;
63+ let keys: HashSet < _ > = handlebar_matches. map ( |m| m[ 1 ] . to_string ( ) ) . collect ( ) ;
6364
6465 if keys. is_empty ( ) {
6566 return ;
6667 }
6768
6869 let mut newcmd = self . cmd . clone ( ) ;
70+
71+ println ! ( "Command is: {}" , & newcmd) ;
72+
6973 for key in keys {
70- let value = Self :: get_arg ( key) ;
74+ let value = Self :: get_arg ( & key) ;
75+ // yes this regex is horrid.
76+ // breakdown of it is:
77+ // the \ are just literal \
78+ // the centre {} is where key is put
79+ // the {{ and }} are escaped { and } respectively
80+ let s = format ! ( r"\{{{}\}}" , key) ;
81+ let re = Regex :: new ( & s) . unwrap ( ) ;
7182 newcmd = re. replace_all ( & newcmd, value) . to_string ( ) ;
7283 println ! ( "Command is now: {}" , newcmd) ;
7384 }
0 commit comments