Skip to content

Instantly share code, notes, and snippets.

@rjstone
Last active September 20, 2016 14:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjstone/3b6617155210357b20541bfc00ca4622 to your computer and use it in GitHub Desktop.
Save rjstone/3b6617155210357b20541bfc00ca4622 to your computer and use it in GitHub Desktop.
Get cdn.rawgit.com hash URLs for most recent commit of files in git repo.
#!/bin/bash
# Get cdn.rawgit.com hash URLs for most recent commit of files in git repo.
# 1) cd to root directory of repository
# 2) run script on one or more filenames.
# Your working dir must be repo root or the URLs will be wrong.
# If you have 'globstar' enabled and your shell supports it, run with ** for recursion.
for f in $@
do
url=`git ls-remote --get-url | sed 's#\.git$##' | sed 's#//github.com/#//cdn.rawgit.com/#'`
hashpart=`git log --max-count=1 --format="%H" "$f"`
if [[ -z $hashpart ]]; then
continue;
fi
echo $url/$hashpart/$f
done
@rjstone
Copy link
Author

rjstone commented Sep 20, 2016

Works in linux bash, windows 'gitbash' (mingw64), and I'd be surprised if it didn't work in OS X too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment