#!/bin/zsh

local dry="0"

execute() {
    log "execute $@"
    [[ $dry != "1" ]] && "$@"
}

log() {
    [[ $dry != "1" ]] && echo "$@" || echo "[DRY RUN]: $@"
}

while [[ $# > 0 ]]; do
    [[ $1 == "--dry" ]] && dry="1"
    shift
done

log "---------------- dotfiles ----------------"

copy_dir() {
    local from=$1
    local to=$2
    pushd $from > /dev/null
    local dirs=(`find . -mindepth 1 -maxdepth 1 -type d`)
    for dir in $dirs; do
        [[ -d $to/$dir ]] && execute rm -rf $to/$dir
        execute cp -rp $dir $to/$dir
    done
    popd > /dev/null
}

copy_file() {
    local from=$1
    local to=$2
    local filename=$(basename $from)
    [[ -e $to/$filename ]] && execute rm $to/$filename
    execute cp -p $from $to/$filename
}

copy_dir src_files/.config $HOME/.config
copy_dir src_files/.local $HOME/.local

#copy_file src_files/.example_file $HOME