From 2e8b176c5f4d93bc614cb9ff6808e5011bb2e103 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 7 Jun 2026 20:48:36 +0300 Subject: Detect bash using shebang --- src/renderer.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/renderer.rs b/src/renderer.rs index 164012e..ad5201f 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -153,10 +153,14 @@ fn detect_language(filename: &Path, contents: &str) -> &'static str { Some("py") => "python", Some("json") => "json", _ => { - if let Some(first_line) = contents.lines().next() - && first_line.contains("python") - { - return "python"; + if let Some(first_line) = contents.lines().next() { + if first_line.contains("python") + { + return "python"; + } + if first_line.contains("bash") { + return "bash"; + } } "" } @@ -300,6 +304,18 @@ mod tests { assert_eq!(String::from_utf8(output).unwrap(), expected); } + #[test] + fn bash_file_detected_from_shebang() { + let mut output = Vec::new(); + let mut renderer = Renderer::new(&mut output); + + let input = Cursor::new("#! /bin/bash\necho hello"); + renderer.render_file(Path::new("hello"), input).unwrap(); + let expected = "\n## File: hello\n```bash\n#! /bin/bash\necho hello\n```\n"; + + assert_eq!(String::from_utf8(output).unwrap(), expected); + } + #[test] fn python_file_detected_from_shebang() { let mut output = Vec::new(); -- cgit v1.3.1