Skip to content

Instantly share code, notes, and snippets.

@archevel
Last active December 17, 2015 00:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archevel/5518986 to your computer and use it in GitHub Desktop.
Save archevel/5518986 to your computer and use it in GitHub Desktop.
Gistit is a bashscript for instantly uploading selected text to github and placing the url to that gist in your clipboard. It relies on curl, xclip, python, sed, grep and notify-send. Use f.i. xbindkeys-config to add a keybinding to the script and you've got instant sharing. The script takes one parameter which is a OAuth token for github.
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No OAuth token supplied. Create one with: "
echo "curl -u 'YOUR_GIT_USERNAME' -d '{\"scopes\":[\"gist\"],\"note\":\"Help example\"}' https://api.github.com/authorizations"
echo "Use the token value that is shown in the json output."
else
URL=$(xclip -o | python -c "import sys, json; print json.dumps({ 'public': True, 'files': { 'gistit.txt': { 'content': sys.stdin.read() } } })" | curl -H "Authorization: token $1" https://api.github.com/gists -d @- 2>&1 | grep -E '"html_url": ".*gist.*' | sed 's/.*html_url": "\([^ ]*gist[^"]*\)",/\1/')
echo $URL | xclip -i -selection clipboard
notify-send --category="transfer.complete" "Gist uploaded" $URL
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment