Skip to content

Instantly share code, notes, and snippets.

@fluffywaffles
Created October 10, 2019 00:22
Show Gist options
  • Save fluffywaffles/416b058bbe50f4e3437ba374e07f3c4c to your computer and use it in GitHub Desktop.
Save fluffywaffles/416b058bbe50f4e3437ba374e07f3c4c to your computer and use it in GitHub Desktop.
gist.zsh
#!/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