File tree 1 file changed +32
-10
lines changed
1 file changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -96,24 +96,46 @@ impl<'a> Executor<'a> {
96
96
match self {
97
97
Self :: Shebang ( shebang) => {
98
98
let mut n = 0 ;
99
+ let mut iter = recipe. body . iter ( ) . zip ( lines) ;
99
100
100
- for ( i, ( line, evaluated) ) in recipe. body . iter ( ) . zip ( lines) . enumerate ( ) {
101
- if i == 0 {
102
- if shebang. include_shebang_line ( ) {
103
- script. push_str ( evaluated) ;
104
- script. push ( '\n' ) ;
105
- n += 1 ;
106
- }
107
- } else {
108
- while n < line. number && !line. is_shebang ( ) {
101
+ // If shebang line should be included it should be at the top
102
+ if let Some ( ( _line, evaluated) ) = iter. next ( ) {
103
+ if shebang. include_shebang_line ( ) {
104
+ script. push_str ( evaluated) ;
105
+ script. push ( '\n' ) ;
106
+ n += 1 ;
107
+ }
108
+ }
109
+
110
+ // Any shebang line that follows the first should also be at the top
111
+ for ( line, evaluated) in iter. by_ref ( ) {
112
+ let line_is_shebang = line. is_shebang ( ) ;
113
+
114
+ if !line_is_shebang {
115
+ while n < line. number {
109
116
script. push ( '\n' ) ;
110
117
n += 1 ;
111
118
}
119
+ }
120
+ script. push_str ( evaluated) ;
121
+ script. push ( '\n' ) ;
122
+ n += 1 ;
112
123
113
- script. push_str ( evaluated) ;
124
+ if !line_is_shebang {
125
+ break ;
126
+ }
127
+ }
128
+
129
+ // The rest of the script should match justfile line numbers
130
+ for ( line, evaluated) in iter {
131
+ while n < line. number {
114
132
script. push ( '\n' ) ;
115
133
n += 1 ;
116
134
}
135
+
136
+ script. push_str ( evaluated) ;
137
+ script. push ( '\n' ) ;
138
+ n += 1 ;
117
139
}
118
140
}
119
141
Self :: Command ( _) => {
You can’t perform that action at this time.
0 commit comments