#!/usr/bin/env zsh

pushd $HOME

setopt EXTENDED_GLOB

if [[ ! -d dotfiles && ${(L)host} =~ prefect ]]
then
	hg clone ssh://alan@home.alanpearce.co.uk:22222/dotfiles
fi

install-dot () {
	local absolute
	if [[ ${1[-1]} == "/" ]]
	then
		absolute=$PWD/

		if [[ ! -d $1 ]]
		then
			mkdir $1
		fi

	else
		absolute=""
	fi

	for f in $@[2,-1]
	do
		if [[ ! -e $1$f:t ]]
		then
			ln -sf $absolute$f $1$f:t
		fi
	done
}

install-dot .emacs.d/ dotfiles/emacs/*
install-dot . dotfiles/^install(.) dotfiles/zsh/zshrc
install-dot .ssh/ dotfiles/ssh/*
if [[ -d projects/dwm ]]
then
	install-dot projects/dwm/ dotfiles/dwm/*
fi

popd