DEV Community

Cover image for Executing Github Gist files from Linux Shell via cURL 🚀
Thomas Gotwig
Thomas Gotwig

Posted on • Edited on

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! 😊

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