summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-07 20:48:36 +0300
committerA Farzat <a@farzat.xyz>2026-06-07 20:48:36 +0300
commit2e8b176c5f4d93bc614cb9ff6808e5011bb2e103 (patch)
tree092b9f51c13c5b29d35deddfc8b1315498373cc2
parent0d6d889dfe32f793f63027e1d773aebe65c38c6f (diff)
downloadrepo2markdown-2e8b176c5f4d93bc614cb9ff6808e5011bb2e103.tar.gz
repo2markdown-2e8b176c5f4d93bc614cb9ff6808e5011bb2e103.zip
Detect bash using shebang
-rw-r--r--src/renderer.rs24
1 files changed, 20 insertions, 4 deletions
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";
+ }
}
""
}
@@ -301,6 +305,18 @@ mod tests {
}
#[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();
let mut renderer = Renderer::new(&mut output);