#!/bin/bash

# check sudo
if command -v sudo &>/dev/null; then
  SUDO=sudo
else
  SUDO=""
fi

# install package
if command -v yum &>/dev/null; then
  $SUDO yum install -y -q git zsh bash-completion wget unzip tree tmux vim sysstat &> /dev/null
elif command -v apt &>/dev/null; then
  $SUDO apt update -qq &>/dev/null
  $SUDO apt install -y git zsh bash-completion wget unzip tree tmux vim sysstat &> /dev/null
else
  echo "[ERROR] unsupport os" >&2
  exit 1
fi

# install oh-my-zsh
# git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
# REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh ohmyzsh/tools/install.sh && rm -rf ohmyzsh
REPO=sjtug/ohmyzsh REMOTE=https://git.sjtu.edu.cn/${REPO}.git sh -c "$(curl -fsSL https://git.sjtu.edu.cn/sjtug/ohmyzsh/-/raw/master/tools/install.sh\?inline\=false)"

ZSH=$HOME/.oh-my-zsh

# install zsh-syntax-highlighting
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://mirrors.nju.edu.cn/git/zsh-syntax-highlighting.git $ZSH/custom/plugins/zsh-syntax-highlighting

# install zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://mirrors.nju.edu.cn/git/zsh-autosuggestions.git $ZSH/custom/plugins/zsh-autosuggestions

# install zsh-you-should-use
# git clone https://github.com/MichaelAquilina/zsh-you-should-use.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use
# git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use

# replace plugins and theme
cp $HOME/.zshrc $HOME/.zshrc.bak
zsh -c 'source ~/.zshrc && omz plugin enable zsh-autosuggestions zsh-syntax-highlighting sudo'
zsh -c 'source ~/.zshrc && omz theme set ys'

cat >> ~/.zshrc <<UK

## add
zstyle ':omz:update' mode disabled
HIST_STAMPS="yyyy-mm-dd"
alias vi="vim"
UK

source ~/.zshrc