Skip to content

Commit f20f493

Browse files
committed
split iterations
1 parent 1456895 commit f20f493

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/executor.rs

+32-10
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,46 @@ impl<'a> Executor<'a> {
9696
match self {
9797
Self::Shebang(shebang) => {
9898
let mut n = 0;
99+
let mut iter = recipe.body.iter().zip(lines);
99100

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 {
109116
script.push('\n');
110117
n += 1;
111118
}
119+
}
120+
script.push_str(evaluated);
121+
script.push('\n');
122+
n += 1;
112123

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 {
114132
script.push('\n');
115133
n += 1;
116134
}
135+
136+
script.push_str(evaluated);
137+
script.push('\n');
138+
n += 1;
117139
}
118140
}
119141
Self::Command(_) => {

0 commit comments

Comments
 (0)