Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: ./go-script -c 'script.Stdin()...' tool for running these #183

Open
simonw opened this issue Aug 20, 2023 · 5 comments
Open

Comments

@simonw
Copy link

simonw commented Aug 20, 2023

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.goscript

And 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.

@simonw simonw changed the title Suggestion: ./go-script -c 'script...'` tool for running these Suggestion: ./go-script -c 'script...' tool for running these Aug 20, 2023
@simonw simonw changed the title Suggestion: ./go-script -c 'script...' tool for running these Suggestion: ./go-script -c 'script.Stdin()...' tool for running these Aug 20, 2023
@simonw
Copy link
Author

simonw commented Aug 20, 2023

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.

@bitfield
Copy link
Owner

Super nice, thanks @simonw! I'll have a play with this.

@alexbozhenko
Copy link

@simonw have you seen https://github.com/erning/gorun ?

@andrewcrook
Copy link

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

@andrewcrook
Copy link

@alexbozhenko

https://github.com/erning/gorun

looks like exactly what I was looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants