Skip to content

Instantly share code, notes, and snippets.

@readysetawesome
Last active December 13, 2015 23:29
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 readysetawesome/4992208 to your computer and use it in GitHub Desktop.
Save readysetawesome/4992208 to your computer and use it in GitHub Desktop.
Turn the current directory's diff into a gist with a single .diff file (assumes you have osx with "pbcopy" and ruby)
function d2g() {
if [ -z "`git diff`" ] ; then
echo 'There is no diff to publish, brah.'
return
fi
if [ $# -eq 0 ] ; then
echo 'Please provide a name for the file.'
return
fi
curl -H "Authorization: token XXXXtokenWithGistScopeXXXX" -d "{\"description\":\"diff for branch: `git branch | grep \* | sed s/\*\ //g`, created: `date`\",\"public\":false,\"files\":{\"$1.diff\":{\"content\":\"`ruby -e 'require "rubygems";require "json";puts JSON.dump(\`git diff\`)[1..-2]'`\"}}}" https://api.github.com/gists | grep '^ "html_url": "https://gist.github.com' | sed s/\ \ \"html_url\"\:\ \"//g | sed s/\",// | pbcopy
}
# build a github token: curl -u 'username' -d '{"scopes":["gist"],"note":"Helper for quick gist from diff"}' https://api.github.com/authorization
# create a gist with file named monday_project.diff,
# and place the newly created gist URL in my clipboard
d2g monday_project
@readysetawesome
Copy link
Author

my sed statements are slightly fragile - changes to the JSON produced by github's API could break the final bit of this that extracts the new gist URL to the clipboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment