Skip to content

fix(magic_data): detect bash/sh/zsh shell script shebangs as .sh (#150)#151

Open
SAY-5 wants to merge 1 commit into
cdgriffith:masterfrom
SAY-5:fix/issue-150-shell-script-shebangs
Open

fix(magic_data): detect bash/sh/zsh shell script shebangs as .sh (#150)#151
SAY-5 wants to merge 1 commit into
cdgriffith:masterfrom
SAY-5:fix/issue-150-shell-script-shebangs

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 30, 2026

Summary

Fixes #150. magic_data.json had Python and PowerShell shebang patterns but no entries for the much more common Unix shell shebangs, so a file starting with #!/bin/bash was matched only by the generic ascii text fallback and reported as .txt / text/plain. The reporter hit this on a real .sh file with v2.1.1.

Change

puremagic/magic_data.json, add hex-encoded shebang patterns for the standard shells:

  • POSIX sh: #!/bin/sh, #! /bin/sh, #!/usr/bin/sh, #!/usr/bin/env sh\n.sh / application/x-sh
  • Bourne-again (bash): #!/bin/bash, #! /bin/bash, #!/usr/bin/bash, #!/usr/bin/env bash, #!/usr/local/bin/bash.sh / application/x-shellscript
  • Z shell (zsh): #!/bin/zsh, #!/usr/bin/zsh, #!/usr/bin/env zsh\n.sh / application/x-shellscript
  • dash: #!/bin/dash.sh / application/x-sh

The newline-terminated entries (env sh\n, env zsh\n) avoid an over-match where env shell etc. could collide.

Test plan

  • pytest test/, 96 passed (was 95; +1 new test)
  • New test_bash_shebang_detected covers #!/bin/bash, #!/bin/sh, #!/usr/bin/env bash, #!/bin/zsh, all return .sh
  • Existing test_small_stream_error for the python shebang still passes, python entries are unchanged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong mime type for sh ?

1 participant