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";
  shotfile="$(echo "$@")";
  cp "$shotfile" "/gits/shots/$shootyear/$shootmonth";
  shotfilename=$(basename "$shotfile");
  encodedshot="$(python -c 'from urllib import quote; print quote("'"$shotfilename"'").encode("utf-8")')"
  shots+=("https://raw.githubusercontent.com/lmmx/shots/master/$shootyear/$shootmonth/$encodedshot");
}
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 - > /dev/null;
  printf '%s\n' "${shots[@]}";
}

take-shots

gist take-shots:

  • Adds one or more images to git-versioned repository,
  • Commits and pushes,
  • Repeats the URLs to use (percent-encoding characters thanks to Python urllib.quote),
  • Returns to the original directory

make-shots

make-shots just copies the file(s) into the directory (make a commit when you're ready).

See also: getgot, which parses the git status --porcelain output to produce an automated summary message for a git commit. Useful here if you add multiple shots separately with make-shots then want to move everything to origin master.

Clone this wiki locally