Last active
September 20, 2016 14:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works in linux bash, windows 'gitbash' (mingw64), and I'd be surprised if it didn't work in OS X too.