#!/bin/sh

SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)

CONFIG=~/.config
mkdir -p "$CONFIG"

link() {
	src="$1"
	dst="$2"

	if [ -e "$dst" ] || [ -L "$dst" ]; then
		rm -rf "$dst"
	fi

	ln -sf "$src" "$dst"
}

link_neovim() {
	link "$SCRIPT_DIR/nvim" "$CONFIG/nvim"
}

link_zsh() {
	link "$SCRIPT_DIR/zsh/zshenv.home" "$HOME/.zshenv"

	mkdir -p "$CONFIG/zsh"
	link "$SCRIPT_DIR/zsh/zshrc" "$CONFIG/zsh/.zshrc"
	link "$SCRIPT_DIR/zsh/zshenv" "$CONFIG/zsh/.zshenv"
	link "$SCRIPT_DIR/zsh/zprofile" "$CONFIG/zsh/.zprofile"
}

# abook
mkdir -p ~/.abook
cp abook/abookrc ~/.abook

# tmux
cp -R tmux "$CONFIG"

# tmuxp
cp -R tmuxp "$CONFIG"

# nvim
link_neovim()

# vit
cp -R vit "$CONFIG"

# mpd
cp -R mpd "$CONFIG"

# ncmpcpp
cp -R ncmpcpp "$CONFIG"

# taskwarrior
mkdir -p "$CONFIG/task"
cp taskwarrior/taskrc "$CONFIG/task/taskrc"

# zsh
link_zsh()

# git
cp git/gitconfig ~/.gitconfig

# gdb
mkdir -p "$CONFIG/gdb"
cp gdb/gdbinit "$CONFIG/gdb/gdbinit"

# X11
cp X11/xinitrc ~/.xinitrc

# Newsboat
cp -R newsboat "$CONFIG"

# wyrd
cp wyrd/wyrdrc ~/.wyrdrc

# nvi
cp nexrc/nexrc ~/.nexrc

# mailcap
cp mailcap/mailcap ~/.mailcap

# npmrc
cp -n npm/npmrc ~/.npmrc

