DEV Community

Cover image for Executing Github Gist files from Linux Shell via cURL πŸš€
Thomas Gotwig
Thomas Gotwig

Posted on β€’ Edited on

6 1

Executing Github Gist files from Linux Shell via cURL πŸš€

We have two different URL options to fetch a Github Gist file via cURL:

  1. gist.githubusercontent.com
  2. api.github.com

The second one is a bit more work, but always instant up-to-date! 🌟

1️⃣ gist.githubusercontent.com

curl -s https://gist.githubusercontent.com/[user]/[gist_id]/raw/[gist_file]?_=$(uuidgen) \
| bash
Enter fullscreen mode Exit fullscreen mode
🌍 Hello World!
Enter fullscreen mode Exit fullscreen mode

But this can run a older version of the file πŸ˜–

2️⃣ api.github.com

πŸ”§ Fix limitations of api.github.com

Using api.github.com comes with rate-limiting per hour:

curl -I -s https://api.github.com/users/[user] | grep x-ratelimit
Enter fullscreen mode Exit fullscreen mode
x-ratelimit-limit: 60
x-ratelimit-remaining: 59
x-ratelimit-reset: 1636928776
x-ratelimit-resource: core
x-ratelimit-used: 1
Enter fullscreen mode Exit fullscreen mode

However, we can get around this strong limitation by using a PAT:

curl -I -s -u <user>:<pat> \
    https://api.github.com/users/[user] | grep x-ratelimit
Enter fullscreen mode Exit fullscreen mode
x-ratelimit-limit: 5000
x-ratelimit-remaining: 4999
x-ratelimit-reset: 1636928894
x-ratelimit-used: 1
x-ratelimit-resource: core
Enter fullscreen mode Exit fullscreen mode

πŸš€ Executing the Gist file!

curl -s -u <user>:<pat> \
    "https://api.github.com/gists/[gist_id]?_=$(uuidgen)" \
    | jq --raw-output '.files."<GIST_FILE>".content' | bash
Enter fullscreen mode Exit fullscreen mode
🌍 Hello World!
Enter fullscreen mode Exit fullscreen mode

Until now it was always up-to-date! 😊

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil β€” patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (1)

Collapse
 
roneo profile image
Roneo.org β€’

Executing random Gists may have really bad consequences, use this with trusted sources only!

See news.ycombinator.com/item?id=12766049 for examples

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay