Source

dotfiles / setup_links.sh

#!/bin/bash

echo "Setting up dotfiles: ..."
LINK_DIR=`cd $(dirname "$0"); pwd`
echo "Linking from: $LINK_DIR"
echo "Linking to: $HOME"

OS=`uname -s`

if [ $OS == "Darwin" ]; then
    LN="ln -ins"
else
    LN="ln --backup=numbered -ns"
fi

# let's get down to business -
# fail on errors / undefined values
set -e -u

for file in $LINK_DIR/*
do
    case $file in
        *.symlink)
            fname=`echo $file | sed -e 's/^.*\///' -e 's/.symlink$//'`
            echo "linking $file to ~/.$fname"
            $LN $file ~/.$fname
            ;;
        *)
            ;;
    esac
done