From 7ba81d1cc213e89dfa483b4670b7d23698d1a73f Mon Sep 17 00:00:00 2001 From: Eduard Zintz Date: Sun, 4 Sep 2016 07:42:13 +0200 Subject: [PATCH] Added simple installer --- install.zsh | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 install.zsh diff --git a/install.zsh b/install.zsh new file mode 100755 index 00000000..a5a09ef3 --- /dev/null +++ b/install.zsh @@ -0,0 +1,98 @@ +#!/usr/bin/env zsh +setopt PIPEFAIL +setopt EXTENDED_GLOB +# setopt XTRACE prompt_subst + +## Ensure colors are available. +autoload -U colors && colors + +PREZTO_DIRECTORY="${ZDOTDIR:-$HOME}/.zprezto" +PREZTO_GIT_REMOTE="https://github.com/ezintz/prezto.git" + +function is_osx { + if [[ "$OSTYPE" != darwin* ]]; then + return 1 + fi + + return 0 +} + +function is_linux { + if [[ "$OSTYPE" != linux* ]]; then + return 1 + fi + + return 0 +} + +function print_header { + printf "\n${fg[blue]}%s${reset_color}\n" "$@" +} + +function print_success { + printf "${fg[green]}✓ %s${reset_color}\n" "$@" +} + +function print_notice { + printf "${fg[yellow]}i %s${reset_color}\n" "$@" +} + +function print_warning { + printf "${fg[magenta]}! %s${reset_color}\n" "$@" +} + +function print_error { + printf "${fg[red]}x %s${reset_color}\n" "$@" +} + +function print_question { + printf "${fg[cyan]}? %s${reset_color}\n" "$@" +} + +function seek_confirmation { + print_warning "$@" + read -q "REPLY?${fg[cyan]}? Continue? (y/n)${reset_color} " -n 1 + printf "\n" +} + +function is_confirmed { + if [[ "$REPLY" =~ ^[Yy]$ ]]; then + return 0 + fi + + return 1 +} + +function cleanup { + print_header "Cleanup" +} + +TRAPINT() { + print "" + print_error "Caught SIGINT, aborting." + cleanup + return $(( 128 + $1 )) +} + +print_header "Prezto — Instantly Awesome Zsh" +seek_confirmation "Do you want to proceed with the installation" +if is_confirmed; then + print_notice "Cloning prezto to $PREZTO_DIRECTORY ..." + if [[ ! -d $PREZTO_DIRECTORY ]]; then + git clone --recursive "$PREZTO_GIT_REMOTE" "$PREZTO_DIRECTORY" + fi + print_success "... done!" + + print_notice "Creating sym links for prezto rcfiles ..." + for rcfile in "$PREZTO_DIRECTORY"/runcoms/^README.md(.N); do + tarfile="${ZDOTDIR:-$HOME}/.${rcfile:t}" + if [[ -f "$tarfile" ]]; then + print_warning "$tarfile already exists, creating a backup as ${tarfile}.backup" + mv "$tarfile" "${tarfile}.backup" + fi + ln -s "$rcfile" "$tarfile" + done + print_success "... done!" +else + print_error "Installation aborted." +fi