#!/bin/bash

set -e

# Backup existing configs
if [ -e "$HOME/.tmux.conf" ]; then
  printf "Found existing .tmux.conf in your \$HOME directory. Will create a backup at $HOME/.tmux.conf.bak\n"
fi

cp -f "$HOME/.tmux.conf" "$HOME/.tmux.conf.bak" 2>/dev/null || true

if [ -e "$HOME/.zshrc" ]; then
  printf "Found existing .zshrc in your \$HOME directory. Will create a backup at $HOME/.zshrc.bak\n"
fi

cp -f "$HOME/.zshrc" "$HOME/.zshrc.bak" 2>/dev/null || true

if [ -e "$HOME/.vimrc" ]; then
  printf "Found existing .vimrc in your \$HOME directory. Will create a backup at $HOME/.vimrc.bak\n"
fi

cp -f "$HOME/.vimrc" "$HOME/.vimrc.bak" 2>/dev/null || true

# Create symlinks
ln -sf .dots/tmux/tmux.conf "$HOME"/.tmux.conf
ln -sf .dots/zshrc "$HOME"/.zshrc
ln -sf .dots/vim/vimrc "$HOME"/.vimrc

# Initialise tmux plugin manager (https://github.com/tmux-plugins/tpm)
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

printf "OK: Completed\n"
