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:

  • 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 just copies the file(s) into the directory (make a commit when you're ready)

gist

Clone this wiki locally