#!/bin/sh
#
# YADM Bootstrap
# @CharlesDanesi

case $(uname -s) in
   Darwin)

      # Install Homebrew
      if ! command -v brew >/dev/null 2>&1; then
         echo "Installing Homebrew"
         /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      fi
   
      if [ -f "$HOME/.Brewfile" ]; then
         echo "Installing/Updating homebrew bundle"
         brew bundle --global
      fi
      ;;
      
   Linux)
   
      # First, we need to distinguish between Arch and Debian/Ubuntu
      # I'm not sure the best way to do this yet, but as I primarily use Arch and
      # Debian based distros, I'm going to separate them by package manager..
      
      if [ ! command -v pacman >/dev/null 2>&1 ]; then # Arch-based
   
         # Add BlackArch repositories
         if [ ! -f /etc/blackarch-mirrorlist ]; then
            echo "Installing BlackArch repositories"
            curl -O https://blackarch.org/strap.sh && sudo sh ./strap.sh
         fi
   
      elif [ $(which apt-get) || $(which apt) ]; then # Debian-based

         echo "nothing to do yet"
   
      else

         echo "nothing to do yet"
   
      fi
      ;;

   *) ;;
esac

echo "Setting up ZSH"
if ! [ -d "$HOME/.zsh" ]; then
   mkdir "$HOME/.zsh"
fi

if ! [ -d "$HOME/.zsh/zsh-autosuggestions" ]; then
   echo "Installing zsh-autosuggestions"
   git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.zsh/zsh-autosuggestions
fi

if ! [ -d "$HOME/.zsh/zsh-syntax-highlighting" ]; then
   echo "Installing zsh-syntax-highlighting"
   git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.zsh/zsh-syntax-highlighting
fi

if ! [ -d "$HOME/.zsh/zsh-completions" ]; then
   echo "Installing zsh-completions"
   git clone https://github.com/zsh-users/zsh-completions.git $HOME/.zsh/zsh-completions
   [[ ! -f $HOME/.zcompdump ]] || rm $HOME/.zcompdump
   echo "Setting up zsh completions"
   compinit
fi

if ! [ -d "$HOME/.zsh/zsh-vi-mode" ]; then
   echo "Installing zsh-vi-mode"
   git clone https://github.com/jeffreytse/zsh-vi-mode.git $HOME/.zsh/zsh-vi-mode
fi

echo "Setting yadm repo origin to SSH"
yadm remote set-url origin "git@github.com:cdanesi/dotfiles.git"
