diff --git a/src/main.rs b/src/main.rs index b0095ce..30e183d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,8 @@ fn needs_compilation(script_name: &str) -> bool { true } fn output_filename(script_name: &str) -> String { - format!(".{}.compiled", script_name.replace("./", "")) + let (dir, base_filename) = script_name.rsplit_once("/").unwrap(); + format!("{}/.{}.compiled", dir, base_filename) } fn run_compiled(script_name: &str) { @@ -88,7 +89,7 @@ fn parse_bash_command( } code.push_str("\")"); let peek = iter.peek(); - if peek.is_none() || peek.contains(&&' ') || peek.contains(&&'\n') { + if !is_expr && (peek.is_none() || peek.contains(&&' ') || peek.contains(&&'\n')) { code.push(';'); } Ok(()) @@ -138,6 +139,12 @@ fn main() { if (c == 'i' && iter.peek().contains(&&'f')) || (c == '=' && !iter.peek().contains(&&'=')) { is_expr = true; + } else if c == 'f' && iter.peek().contains(&&'o') { + iter.next(); + code.push('o'); + if iter.peek().contains(&&'r') { + is_expr = true; + } } else if (c == '{' || c == ';') && is_expr { is_expr = false; } else if c == '\n' && iter.peek().is_some() { @@ -156,9 +163,11 @@ fn main() -> Result<()> { run_compiled(&script_name); return Ok(()); } + + let script_base_filename = script_name.split("/").last().unwrap(); let code = collect_code(&script_name)?; let code_filename = format!("/tmp/{}-rush.rs", - script_name.replace("./", "").replace(".", "-")); + script_base_filename.replace(".", "-")); let mut file = File::create(&code_filename)?; file.write_all(code.as_bytes())?;