@@ -104,14 +104,33 @@ private static List<KeyValuePair<HostEntry, List<string>>> LoadCommands(string c
104104 string cleanedLine ;
105105 bool isHostLine = false ;
106106 int lineIndex = 0 ;
107+ Dictionary < string , string > replacers = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
108+
107109 foreach ( string line in File . ReadAllLines ( commandFile ) )
108110 {
111+ // clean and trim
109112 cleanedLine = line . Trim ( ) ;
110113 int pos = cleanedLine . IndexOf ( '#' ) ;
111114 if ( pos >= 0 )
112115 {
113116 cleanedLine = cleanedLine . Substring ( 0 , pos ) . Trim ( ) ;
114117 }
118+
119+ // replace any find and replace directives
120+ foreach ( var kv in replacers )
121+ {
122+ cleanedLine = cleanedLine . Replace ( kv . Key , kv . Value , StringComparison . OrdinalIgnoreCase ) ;
123+ }
124+
125+ // look for defines ($...$=value)
126+ Match replacer = Regex . Match ( cleanedLine , @"(?<name>\$[^\$]+\$)\s*=\s*(?<value>.+)" , RegexOptions . IgnoreCase | RegexOptions . Singleline ) ;
127+ if ( replacer . Success )
128+ {
129+ replacers [ replacer . Groups [ "name" ] . Value ] = replacer . Groups [ "value" ] . Value ;
130+ continue ;
131+ }
132+
133+ // check if this is a host
115134 isHostLine = cleanedLine . StartsWith ( "$host" , StringComparison . OrdinalIgnoreCase ) ;
116135 if ( currentEntry != null && ( cleanedLine . Length == 0 || isHostLine ) )
117136 {
@@ -125,6 +144,7 @@ private static List<KeyValuePair<HostEntry, List<string>>> LoadCommands(string c
125144 }
126145 if ( isHostLine )
127146 {
147+ // found a host, set the current entry
128148 string [ ] pieces = cleanedLine . Split ( ' ' ) ;
129149 if ( pieces . Length < 3 )
130150 {
@@ -161,6 +181,7 @@ private static List<KeyValuePair<HostEntry, List<string>>> LoadCommands(string c
161181 lines . AddRange ( inheritedLines ) ;
162182 if ( currentEntry != null && lines . Count != 0 )
163183 {
184+ // add commands for this host
164185 commands . Add ( new KeyValuePair < HostEntry , List < string > > ( currentEntry , lines ) ) ;
165186 }
166187 return commands ;
0 commit comments