Skip to content

Instantly share code, notes, and snippets.

@fluffywaffles
Created August 9, 2019 01:59
Show Gist options
  • Save fluffywaffles/c772131ecccbc08aca7f5d1726ecdc59 to your computer and use it in GitHub Desktop.
Save fluffywaffles/c772131ecccbc08aca7f5d1726ecdc59 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! :)
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