-
-
Save leo424y/98850096c6cb77a52e89b52020b3aa89 to your computer and use it in GitHub Desktop.
gistpost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Purpose : post a file as github gist | |
| # Author : Carl Verbiest | |
| typeset local | |
| script=$0 | |
| script_dir=${script%/*} | |
| script=${script##*/} | |
| [ -f ~/.ssh/github.env ] && . ~/.ssh/github.env | |
| TEE="" | |
| PUBLIC=false | |
| Usage() { | |
| cat <<END | |
| Usage $0 [-u user] [-p password] [-w] file ... | |
| -u : username, default \$GITHUB_USER | |
| -p : password, default \$GITHUB_PASSWORD | |
| -w : show it to the world = public gist | |
| -d : debug | |
| END | |
| exit 1 | |
| } | |
| postfile() { | |
| ff=$1 | |
| fn=${ff##*/} | |
| cat <<END | |
| { | |
| "description":"$fn", | |
| "public":$PUBLIC, | |
| "files": { | |
| "$fn": { | |
| "content":"$(sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/$/\\n/' <$ff)" | |
| } | |
| } | |
| } | |
| END | |
| } | |
| set -- `getopt u:p:wd $*` | |
| if [ $? != 0 ] | |
| then | |
| Usage | |
| fi | |
| for i in $* | |
| do | |
| case $i in | |
| -u) GITHUB_USER=$2; shift; shift;; | |
| -p) GITHUB_PASSWORD=$2; shift; shift;; | |
| -w) PUBLIC=true; shift;; | |
| -d) TEE="| tee"; shift;; | |
| --) shift; break;; | |
| esac | |
| done | |
| [ ! -f "$1" ] && Usage | |
| for file in $* | |
| do | |
| echo Posting $file | |
| postfile $file $TEE | curl --user "$GITHUB_USER:$GITHUB_PASSWORD" --data @- https://api.github.com/gists | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment