Suggestion: `./go-script -c 'script.Stdin()...'` tool for running these
simonw opened this issue · 5 comments
I built a little Bash script to let you do this: https://til.simonwillison.net/bash/go-script
cat file.txt | ./goscript.sh -c 'script.Stdin().Column(1).Freq().First(10).Stdout()'It supports this too:
cat file.txt | ./goscript.sh top10.goscriptAnd this, saved as top10.goscript and made executable:
#!/tmp/goscript.sh
script.Stdin().Column(1).Freq().First(10).Stdout()
Then run like this:
cat file.txt | ./top10.goscript It's a fun little hack in Bash, but maybe something like this could be useful as an actual Go program distributed as part of this project.
Fun follow-up idea: https://fedi.simonwillison.net/@simon/110922873440211227
you could hash the script body, create
~/.cache/goscript/HASH/script.go, save a compiled binary to that folder and run that directly in the future.
@simonw have you seen https://github.com/erning/gorun ?
Was just going to suggest something similar but in the form of a hash bang in the go file used as a script ....
#! /usr/bin/env go-script
- checks for changes and if in binary cache,
- compiles
- and then caches. - runs from cache