#!/usr/bin/env bash set -e readonly DCP="${HOME}/.dcp" readonly DOTVIM_DIR="${HOME}/.vim" readonly ZSH="${HOME}/.oh-my-zsh" readonly ZSH_HLT_DIR="${ZSH}/custom/plugins/zsh-syntax-highlighting" if [[ "$(id -un)" = "danpoggi" && -z "${DCP_CLONE_HTTPS}" ]]; then readonly GIT_BASE="git@github.com:dpoggi" else readonly GIT_BASE="https://github.com/dpoggi" fi readonly ZSH_HLT_GIT="https://github.com/zsh-users/zsh-syntax-highlighting.git" log_info() { printf "\033[0;34m[%s]:\033[0m %s\n" \ "$(date "+%Y-%m-%d %H:%M:%S")" \ "$*" } log_error() { printf >&2 "\033[1;37;41m[%s]:\033[0m %s\n" \ "$(date "+%Y-%m-%d %H:%M:%S")" \ "$*" } fatal() { log_error "$@" return 1 } clone_repo() { local repo_url="$1" local repo_name="$(basename "${repo_url}" ".git")" local clone_dir="$2" if [[ ! -e "${clone_dir}" ]]; then log_info "Cloning ${repo_name} into ${clone_dir}..." git clone --quiet \ --recursive \ "${repo_url}" \ "${clone_dir}" \ > /dev/null 2>&1 log_info "Finished." else log_info "${clone_dir} already exists, skipping..." fi printf >&2 "\n" } main() { if ! hash git 2> /dev/null; then fatal "Git is required." fi clone_repo "${GIT_BASE}/dcp.git" "${DCP}" clone_repo "${GIT_BASE}/dotvim.git" "${DOTVIM_DIR}" clone_repo "${GIT_BASE}/oh-my-zsh.git" "${ZSH}" clone_repo "${ZSH_HLT_GIT}" "${ZSH_HLT_DIR}" log_info "Running update script..." export PATH="${PATH}:${DCP}/bin" printf >&2 "\n" "${DCP}/bin/dcp-update" printf >&2 "\n" log_info "Tip: restart your terminal, or do \`exec $(basename "${SHELL}")' now." } main "$@"