Comment by fsmv
2 months ago
I made one of these too! I decided not to use // because I use gofmt auto formatting in my editor and it puts a space between the // and the usr. This one isn't changed by gofmt:
/*?sr/bin/env go run "$0" "$@"; exit $? #*/
This is a sweet idea, thank you!
My suggestion for minimal/readable:
I wonder if bash has a way to override the default function calling mechanism. Since functions in bashrc would probably take priority, maybe something like this could be possible: (psuedo code)
```
execve(path, args) {
}
```
Then when you run `./script.go`, the function gets called and passes it so `go run`, while everything else goes through the existing execve function. That would be interesting, because then you could do this with absolutely anything.
`./script.rb`
`./script.py`
`./script.c`
etc
It works, but the best in me I cannot explain fully first 3 symbols. /*?sr/bin/env finds /usr by expanding *? to a first matching directory. But why not just /*usr/ instead?
I think I was just trying to minimize accidentally matching the wrong thing. Both do work though and it is kinda nice to be more readable.
If I remember right I think ? Is exactly one character only, or maybe it does non greedy .