Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Created February 7, 2009 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedamage/59759 to your computer and use it in GitHub Desktop.
Save mikedamage/59759 to your computer and use it in GitHub Desktop.
Get a Gist by ID and copy to clipboard.
// Get & copy a Gist by ID
CmdUtils.CreateCommand({
name: "gist-copy",
icon: "http://gist.github.com/favicon.ico",
author: {name: "Mike Green", email: "mike.is.green@gmail.com"},
takes: {"gist": noun_arb_text},
preview: function(pblock, theGist) {
var urlTemplate = "http://gist.github.com/${gist}.txt";
var gistURL = CmdUtils.renderTemplate(urlTemplate, {gist: theGist.text});
CmdUtils.previewGet(pblock, gistURL, {}, function(data) {
pblock.innerHTML = data;
});
},
execute: function(theGist) {
var urlTemplate = "http://gist.github.com/${gist}.txt";
var gistURL = CmdUtils.renderTemplate(urlTemplate, {gist: theGist.text});
jQuery.get(gistURL, {}, function(data) {
CmdUtils.copyToClipboard(data);
displayMessage("Gist " + theGist.text + " copied to clipboard.");
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment