#!/bin/sh

# ============================================
# mklinks
# --------------------------------------------
# This script will go through each sub-folder
# of DOTROOT and create symbolic link to it
# under your HOME named with "." prefix.
#
# This is useful for sharing your dotfiles
# (e.g. using service like Dropbox or keeping
# them in a shared VCS repository like git)
#
#    DOTROOT - path where your shared dot-files
#              are.
#    PREFIX  - where you want your links to
#              dot-files to be created ($HOME
#              by default)
#
# --------------------------------------------
# By Alois Mahdal; no warranty
# ============================================


if [ -z "$1" ];
    then echo "usage: $0: DOTROOT [PREFIX]";
    exit 1;
fi;

dotroot=$1
prefix=$HOME

if [ -n "$2" ];
    then prefix=$2;
fi;


ls $dotroot | while read item;
do
    source=$dotroot/$item;
    target=$prefix/.$item;
    if [ -e $target ];
    then
        echo "target exists: $target" 1>&2;
    else
        ln -s $source $target;
    fi;
done;