Created
August 9, 2019 01:59
-
-
Save fluffywaffles/c772131ecccbc08aca7f5d1726ecdc59 to your computer and use it in GitHub Desktop.
gist.zsh
This file contains 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/zsh | |
function json_quote { | |
node -e "console.log(JSON.stringify(fs.readFileSync('$1').toString()))" | |
} | |
github_gist_token=$(cat ~/.github-gist-token) | |
file=$1 | |
quoted_file_contents=$(json_quote $file) | |
file_name=$(basename $file) | |
description=${2:-$file_name} | |
printf -v json '{ | |
"public": true, | |
"description": "%s", | |
"files": { "%s": { "content": %s } } | |
}' $description $file_name $quoted_file_contents | |
response=$(mktemp) | |
>$response curl --silent \ | |
-H "Authorization: token $github_gist_token" \ | |
-X POST \ | |
-d "$json" \ | |
"https://api.github.com/gists" | |
echo "yooooou got it, champ!" | |
# NOTE(jordan): this is NOT very robust! :) | |
cat $response \ | |
| grep "\"html_url\":" \ | |
| grep "https://gist.github.com/" \ | |
| cut -d: -f2- \ | |
| tr -d '", ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment