gorun icon indicating copy to clipboard operation
gorun copied to clipboard

gorun fmt

Open ericcurtin opened this issue 8 years ago • 3 comments

A C/C++ programmer primarily, looking to learn something new, golang! One of the things I first thought is what great potential it had as a statically typed scripting language! And I really like how you cache compiled binaries here, pretty cool.

Anyway long story short... I'd like to introduce a "gorun fmt" option to format my gorun scripts... Because if you pass through normal go fmt it doesn't like the shebang of course:

go fmt hello_world.go 
can't load package: package main: 
hello_world.go:1:1: illegal character U+0023 '#

If I open a PR would you except a "gorun fmt" option? Don't want to waste effort if it wouldn't be accepted!

ericcurtin avatar Jan 05 '18 18:01 ericcurtin

@ericcurtin one option is to run it as comments, then you can run go fmt on it fine:

//usr/bin/env gorun "$0" "$@"; exit "$?"

package main

func main() {
	println("Hello worldz!")
}

For various other solutions and tradeoffs see: https://gist.github.com/posener/73ffd326d88483df6b1cb66e8ed1e0bd

dougnukem avatar Jan 19 '19 00:01 dougnukem

Somehow this also works and gofmt won't change the code. It adds a space after the comment

// / 2>/dev/null ; gorun "$0" "$@" ; exit $?

jackielii avatar Mar 10 '23 12:03 jackielii