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.
READER DISCOUNTSave $50 on terminal.training
I've published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today.
$49 - only from this link
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?
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 the
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 the
echocommand piped into a file as named by the
.filenameproperty 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
evaled 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.