#!/usr/bin/env bash

DOTFILES=$HOME/.dotfiles

if [[ ! -d ~/.oh-my-zsh ]]; then
    echo -e "\nInstall oh-my-zsh"
    echo "============================="
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    ln -s $DOTFILES/zsh/{custom,aliases}.zsh ~/.oh-my-zsh/custom/
    ln -s $DOTFILES/zsh/custom-agnoster.zsh-theme ~/.oh-my-zsh/custom/themes/agnoster.zsh-theme
fi

echo -e "\nCreating symlinks"
echo "=============================="
linkables=$( find -H "$DOTFILES" -maxdepth 3 -name '*.symlink' )
for file in $linkables ; do
    target="$HOME/.$( basename $file '.symlink' )"
    if [ -e $target ]; then
        echo "~${target#$HOME} already exists... Skipping."
    else
        echo "Creating symlink for $file"
        ln -s $file $target
    fi
done

# Vim folders
echo -e "\eLinking vim files and folders"
mkdir "$HOME/.config/nvim"
ln "$DOTFILES/init.vim" "$HOME/.config/nvim"
linkables=$( find vim -mindepth 1 -type d -exec basename {} \; )
mkdir ~/.config/nvim
for folder in $linkables ; do
    target="$HOME/.config/nvim/$folder"
    if [ -e $target ]; then
        echo "~${target#$HOME/.vim} already exists... Skipping."
    else
        echo "Creating symlink for $folder"
        ln -s $DOTFILES/vim/$folder $target
    fi
done