Tuesday, March 20, 2012

Gister - gists at your fingertips

So long time no post... been busy with a lot of real life stuff.

Introducing: Gister

Luckily I got some time to play again on Sunday night - and the result is a script called gister

gister can save, cat arbitrary files from gists, or execute them if they have #! at the top.

Why? I hear you asking silently to yourself. Well, the inspiration behind this was as follows: I was busy writing a script to execute a command for each commit in the history of a git repository. This resulted in the following script/gist: git-foreach.sh

Simple enough. This gist clones the repository, goes through EVERY commit in the repo (for all branches), and then executes a script that was passed in as an argument for each of the commits. So this resulted in yet another script, stored as a gist on github.

Cool, that's handy. Now combining the two scripts we get a nice newline seperated list of the number of files for each commit. Now let's say we want to plot this. Lets use gnuplot. But everytime I use gnuplot, I need to go re-study the syntax of the plot files for gnuplot. And everytime I do that, I end up with basically the same script that I've written 70 times in the past. So I decided, screw it. I need a better plan.

So that's where gister comes in. The idea behind this is to store all these handy scripts that you write, as gists on your github account, and then run them from the internet, right in your shell. So no need to download anything, or to put something in your PATH everytime you want to run a small script. You just install gister once, and you can cat/run/store any public gist on github. This also works for OTHER peole's gists as well, of course. So we can all sharea nd publish our neat little scripts online for people to use.

So go to and install gister. Download the single .sh file, give it +x permissions and (optionally) put it on your path, and start playing with it. I suggest creating a $HOME/bin directory, placing gister there, and then putting it on your path in your .bashrc . This will probably be where gister installs binaries one day should it get that functionality.

Here are some things you can do with it:

Get a response from the magic 8ball:

Get a gnuplot of the number of lines over time in any git repository (you need to chdir to the root of the git repo):

Play a simple maze game in your terminal:

It also supports passing arguments to the online gist, but appending a "-" followed by the arb arguments:

So there you have it. Play with a bit. It would be awesome if you guys could find any other interesting things you can run with gister on github. Remember the limitations though. The Gist MUST have a filename, and multi-file gists will not work at the moment. Of course, if you want to help out, here is what's needed in order of importance:

  • 'Anonymous' gists - ie. gists with no filename, just an id.
  • Multi-file gists

Those are all immediate featues, adding value which will be valuable later regardless. Now, what about the future? I'm thinking along this following lines:

  • Ability to install the gists locally, in $HOME/.gister_bin on something. Which can then be on your path.
  • Ability to track versions, sort of like a package manager for shell scripts. So gister -u runs through all installed gists and updates them
  • Ability to track not only shell scripts, but arbitrary documents. This needs to work both ways. I want to use gists to store notes, for example. So I would have a gist for all my notes, and install/track it with gister. Whenever I update a file, I use gister to upload all the changes I made.

So play with it a bit, let me know what you think. This was only tested on zsh. Bash should work. Other shells may not work.

No comments:

Post a Comment