Skip to content

fileutil: recognize dash in shebang for -ln=auto - #1307

Merged
mvdan merged 1 commit into
mvdan:masterfrom
risu729:dash-shebang
Apr 8, 2026
Merged

mvdan merged 1 commit into
mvdan:masterfrom
risu729:dash-shebang

Conversation

@risu729

@risu729 risu729 commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

shfmt --find . doesn't list shell files with #!/usr/bin/env dash now.
I generated this PR using Cursor, but confirmed the changes.


Summary

Extend shebang detection to #!/bin/dash and #!/usr/bin/env dash, mapping them to POSIX (same as #!/bin/sh). syntax.LangVariant.Set accepts "dash" so shfmt can apply the dialect when using -ln=auto.

Context

Changes

  • fileutil: add dash to shebangRe.
  • syntax: map dash → LangPOSIX in LangVariant.Set.
  • Tests: fileutil table tests; walk.txtar integration expectations for shebang-dash.

Made with Cursor

Extend shebang detection to #!/bin/dash and #!/usr/bin/env dash, mapping
them to POSIX like #!/bin/sh. LangVariant.Set accepts "dash" so shfmt can
apply the detected dialect.

Related to #622 (shebang allowlist for auto language detection). This is
detection only; dash remains POSIX dialect, not a separate parser mode
(see discussion in #105).

Made-with: Cursor

@mvdan mvdan left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LangVariant.Set("dash") == LangPOSIX is a little odd, but I guess it's not wrong. SGTM

@mvdan

mvdan commented Apr 6, 2026

Copy link
Copy Markdown
Owner

This is not straightforward because dash is a little more than POSIX, e.g. it does include arrays. However, it's definitely not Bash, and it's much closer to POSIX shell than any of the other popular shells in use today.

In fact, we use dash to sanity check our parser tests with LangPOSIX.

So while this is not perfect, it's likely good enough for now.

@mvdan
mvdan merged commit b2c5d6c into mvdan:master Apr 8, 2026
8 checks passed
@risu729
risu729 deleted the dash-shebang branch April 8, 2026 17:59
@risu729

risu729 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

Sorry I missed your comment. Thanks for merging!

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.

2 participants

⌂ 换网址