Skip to content

Image hosting on GitHub

Louis edited this page Apr 25, 2015 · 39 revisions

.bashrc functions to automate image hosting at github.com/lmmx/shots

function take-shot      (){
  # Allow take-shot without versioning: create array if one doesn't exist
  if [ -z ${shots+x} ]; then shots=(); fi
  # ...would leave array lying around so needs wrapper to clean up: `make-shots`
  shootyear="$(date | awk '{print $6}')";
  shootmonth="$(date | awk '{print $2}')";
  mkdir -p "/gits/shots/$shootyear/$shootmonth";
  cp $@ "/gits/shots/$shootyear/$shootmonth";
  shots+=("https://raw.githubusercontent.com/lmmx/shots/master/$shotyear/$shotmonth/$(basename $@)");
}
function make-shots     (){ for shot in "$@"; do take-shot $shot; done; shots=""; }
function take-shots     (){ for shot in "$@"; do take-shot $shot; done; }
function shoot          (){
  shots=();
  take-shots "$@";
  cd /gits/shots/;
  git add .;
  git commit -m "Added $@";
  git push origin master;
  cd -;
  printf '%s\n' "${shots[@]}";
}
  • Adds one or more images to git-versioned repository,
  • Commits and pushes,
  • Repeats the URLs to use (assuming no non-URL-friendly characters in filenames),
  • Returns to the original directory

gist

Clone this wiki locally