Skip to content

Instantly share code, notes, and snippets.

@exapsy
Last active March 31, 2020 03:26
Show Gist options
  • Save exapsy/e58d7a67524516cb6356b2e04f7b94ce to your computer and use it in GitHub Desktop.
Save exapsy/e58d7a67524516cb6356b2e04f7b94ce to your computer and use it in GitHub Desktop.
# Prints a raw file from a github repository
# usage: gitraw johndoe/myrepo README.md
# required: export GITTOKEN, generate a token from github settings
function gitraw {
GITUSER=$(echo $1 | sed -n "s/\([[:alnum:]]\+\)\/.*/\1/gp")
GITREPO=$(echo $1 | sed -n "s/.*\/\([[:alnum:]]\+\)$/\1/gp")
GITCONTENT=$2
if [ -z $1 ]; then
echo "No path given"
else
curl -H "Authorization: token $GITTOKEN" \
-H 'Accept: application/vnd.github.v3.raw' \
-L "https://api.github.com/repos/$GITUSER/$GITREPO/contents/$GITCONTENT"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment