Skip to content

Instantly share code, notes, and snippets.

@agail
Last active January 25, 2020 19:14
Show Gist options
  • Save agail/19fab649c743fe0a7ba00493304c93a4 to your computer and use it in GitHub Desktop.
Save agail/19fab649c743fe0a7ba00493304c93a4 to your computer and use it in GitHub Desktop.
draft
#!/bin/bash
#
# function will create a public gist with file name test.txt containing 'String file contents'
#
# github_user can be Github user name or email address associated with the account.
#
# simple-gist {userid} [gist|gists]
#
gistUrl=https://api.github.com/gists
github_user=$1
awk_jq () { # fallback to awk if jq is missing
if ! [ -x "$(command -v jq)" ]; then
filter=(awk -F "[\"]" '/raw/ {print $4}')
else
filter=(jq --raw-output .files[].raw_url)
fi
}
gist () { # public gist
awk_jq
curl -s -u ${github_user} -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' ${gistUrl} | "${filter[@]}"
}
gists () { # private/secret gist
awk_jq
curl -s -u ${github_user} -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' ${gistUrl} | "${filter[@]}"
}
$2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment