mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.27k stars 345 forks source link

fileutil: should the Shebang be more generic? #846

Open mvdan opened 2 years ago

mvdan commented 2 years ago

Right now, the Shebang API uses a shell-specific regular expression:

https://github.com/mvdan/sh/blob/43a160083ea11d3d02f66c6ac748ae4c64ab4bc3/fileutil/file.go#L16

This will work for shell shebangs like #!/usr/bin/bash, but not for others like #!/usr/bin/python. There's not really a good reason for it; we just didn't write it that way.

It would be neat if the regular expression was made more generic. It should probably return the entire command, so if the input is #!/usr/bin/bash -x, it would return bash -x, where right now it would only return bash. The places where we call Shebang would need to be adjusted.