I've recently been using gists to help debug user issues on nodemon. The process is two parts: firstly getting the original files up into a gist (ideally pared down), and secondly downloading each file to my local dev environment.
Using two tools, I'm able to simplify this workflow pretty nicely, so I can go to gist and back again.
UK EVENTAttend ffconf.org 2024
The conference for people who are passionate about the web. 8 amazing speakers with real human interaction and content you can't just read in a blog post or watch on a tiktok!
£249+VAT - reserve your place today
Caveats first
For the time being, directory structure is not supported, which is a bit of a limitation, but perhaps something like the tree
command mixed in with the tree generation command (I wrote) called eert could help.
Up: to gist
To get files online, you could upload them individually to the gist website, or better than that: install the gist
command line tool.
For Mac users, I'd recommend using the brew install gist
(and get brew, the package installer from brew.sh). Otherwise, gem install gist
(though my own track record for using gem install…
is fairly shaky, so hopefully you have more luck).
Then you specify the files to send up:
$ gist index.js package.json
https://gist.github.com/a24b93601b8b2a68b8e978460bf6e4e1
That URL can/should be then shared on the issue.
Down: from gist
Now for the fun part, pulling a gist down and generating all the individual files in a single command 💪😃
Using jq (a lightweight and flexible command-line JSON processor), a well formed command can use Github's public API for reading gist (though won't work on secret gists unless you also use an auth token…outta scope for this post though).
First, here's the full working command (assuming you've installed jq
and you have curl
on your machine - most do):
$ eval "$(curl -L https://git.io/vbSgz \
| jq -r '.files
| to_entries
| .[].value
| @sh "echo \(.content) > \(.filename)"')"
$ tree
.
├── index.js
└── package.json
What's actually happening?
The jq
is given a "script" to run against the JSON result of the gist API call. You can play with an interactive jq toy I built and see the effects of tweaking the query.
To explain the query:
.files
: reads thefiles
property.to_entries
: transforms the objects into an array that exposes the property from each unique filename into a common property name..[].value
: returns a list (not an array) of objects that contain the filename and contents for plucking.@sh "echo \(.content) > \(.filename)"
: generates a "shell safe" string that is theecho
command piped into a file as named by the.filename
property in our object. The\(.<prop>)
syntax is the template syntax for jq.
This query is passed to jq -r
- the -r
part returns the result as a bare string (rather than quoted as you'll see the result in the Jace tool links).
Finally the entire result is eval
ed through the command line which is the same as copying and pasting each line into the command line.
The result: individual files with the contents from the gists.