Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm rewriting my question, since it appears to not have been clear enough...

I am trying to find a way to pull the content from a github gist and put that content into either the terminal itself, a new document, or appended to an already created document.

To do this, I would like to type in a command in my terminal with syntax similar to the following:

gist <source> <output>

where source is the url to the gist, and output is either terminal or the exact location of a file to create / append the text with.


Original question:

I found a way to post gists to Github in the terminal with a ruby gem, however, I would actually like a way to retrieve those gists, aka, use them as snippets, as well. I'm quite sure it's possible, but I'm not very familiar with the Gist api, and I'm also a bit of a latecomer to the Linux systems.

I'm using Linux Mint 17.1 with Cinnamon, though I do have a live CD for the KDE variation of Linux Mint that I've been testing out. I would prefer an answer that includes both a gui based and cli based solution, as I'm trying to learn to better use CLI.

I know there are gist options for specific editors, but I'd prefer something that doesn't require a specific program to work.

share|improve this question
    
"however, I would actually like a way to retrieve those gists, aka, use them as snippets, as well." I'm not sure what you are asking. You realise that gist correspond to git repositories, right? So you can clone those urls. –  Faheem Mitha Mar 3 at 22:21
    
I don't want to 'clone' them, I want to use them as snippets, meaning, if I write a gist that contains a snippet of code for, say, a bash script, I'd like to be able to pull the text from that gist into whatever I'm writing, just like a snippet. –  Jackie KayE Mar 3 at 22:24
    
By pull do you mean download from the remote repos? –  Faheem Mitha Mar 3 at 22:29

1 Answer 1

up vote 0 down vote accepted

Ok, I think that what you want is a script for downloading a specified gist without the need to use your web browser. Something like this:

#!/bin/sh

# gist-dl.sh: download a Github gist from a specified link to either a
#             standard output (when no second argument passed) or to a
#             specified file (with second argument passed). The first
#             argument is a gist URL and is obligatory

if [ "$1"a = a ]
then
    echo No gist URL passed. Bye
    exit 1
fi

if [ "$2"a = a ]
then
    wget -q -O - "$1"/raw
else
    wget -q -O "$2" "$1"/raw
fi

Usage:

$ # display a gist in terminal
$ ./gist-dl.sh https://gist.github.com/kylejohnson/6c6c0ca2d300ffce4bea
<VirtualHost *:80>
    ServerName zm
    ServerAdmin webmaster@localhost

    DocumentRoot "/var/www/zm"
    <Directory "/var/www/zm">
        Options FollowSymLinks
        AllowOverride All
    </Directory>

    ScriptAlias /cgi-bin/ "/usr/lib/cgi-bin/"
    <Directory "/usr/lib/cgi-bin">
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/zm-error.log
    LogLevel warn
    CustomLog /var/log/apache2/zm-access.log combined
</VirtualHost>
$ # download a gist to GIST.txt
$ ./gist-dl.sh https://gist.github.com/kylejohnson/6c6c0ca2d300ffce4bea GIST.txt
$ cat GIST.txt
<VirtualHost *:80>
    ServerName zm
    ServerAdmin webmaster@localhost

    DocumentRoot "/var/www/zm"
    <Directory "/var/www/zm">
        Options FollowSymLinks
        AllowOverride All
    </Directory>

    ScriptAlias /cgi-bin/ "/usr/lib/cgi-bin/"
    <Directory "/usr/lib/cgi-bin">
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/zm-error.log
    LogLevel warn
    CustomLog /var/log/apache2/zm-access.log combined
</VirtualHost>
share|improve this answer
    
huh, that's almost it, but I don't think that script can append text to a document that's already created... but it's close! I'm not even sure that appending is possible, so I'll grab your script for now, but if anyone finds a way to append that'd be great! –  Jackie KayE Mar 4 at 1:20
    
Well, you can append a gist to a file using redirection with this script like this: ./gist-dl.sh https://gist.github.com/anonymous/cc938f978eda11a0a961 >> FILE. I think that this is the best because apart from that there are 2 possibilities and both are not so good: 1. add a separate 3rd argument for that but would be quite awkward - like append/create 2. always append to a file if it already exists. –  Arkadiusz Drabczyk Mar 4 at 1:30
    
@JackieKayE: if you like this answer please mark it as accepted so that other users will know it's solved –  Arkadiusz Drabczyk Mar 4 at 14:29
    
I don't know how XD –  Jackie KayE Mar 4 at 15:42
    
@JackieKayE: I see you did, thx :) –  Arkadiusz Drabczyk Mar 4 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.