Created
October 10, 2019 00:22
-
-
Save fluffywaffles/416b058bbe50f4e3437ba374e07f3c4c 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! :) | |
node -e " | |
console.log(JSON.parse( | |
require('fs') | |
.readFileSync(process.argv[1]) | |
.toString() | |
).html_url) | |
" $response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment