Repository navigation
fileutil: recognize dash in shebang for -ln=auto - #1307
Merged
Merged
Conversation
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
approved these changes
Apr 1, 2026
mvdan
left a comment
Owner
There was a problem hiding this comment.
LangVariant.Set("dash") == LangPOSIX is a little odd, but I guess it's not wrong. SGTM
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 So while this is not perfect, it's likely good enough for now. |
Contributor
Author
|
Sorry I missed your comment. Thanks for merging! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
shfmt --find .doesn't list shell files with#!/usr/bin/env dashnow.I generated this PR using Cursor, but confirmed the changes.
Summary
Extend shebang detection to
#!/bin/dashand#!/usr/bin/env dash, mapping them to POSIX (same as#!/bin/sh).syntax.LangVariant.Setaccepts"dash"soshfmtcan apply the dialect when using-ln=auto.Context
Changes
fileutil: adddashtoshebangRe.syntax: mapdash→LangPOSIXinLangVariant.Set.fileutiltable tests;walk.txtarintegration expectations forshebang-dash.Made with Cursor