main() { # Use colors, but only if connected to a terminal, and that terminal # supports them. if which tput >/dev/null 2>&1; then ncolors=$(tput colors) fi if [ -t 1 ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then red="$(tput setaf 1)" green="$(tput setaf 2)" yellow="$(tput setaf 3)" blue="$(tput setaf 4)" bold="$(tput bold)" normal="$(tput sgr0)" else red="" green="" yellow="" blue="" bold="" normal="" fi # Only enable exit-on-error after the non-critical colorization stuff, # which may fail on systems lacking tput or terminfo set -e # Check if zsh exists if [ ! "$(grep "/zsh$" "/etc/shells" | wc -l)" = 1 ]; then # try installing from Homebrew if [ ! "$(which -s brew)" = 0 ]; then brew install zsh >/dev/null 2>&1 printf "${yellow}Installing zsh via Homebrew.. ${normal}\n" else printf "${red}Error: zsh isn't available! ${blue}Please install zsh first!${normal}\n" exit 1 fi fi # Check if Zim is already installed if [ -e "${ZDOTDIR:-${HOME}}/.zimrc" ]; then printf "${red}Error: You already have Zim installed!${normal}\n"; exit 1 fi # Check if other frameworks are installed if [ -d "${HOME}/.oh-my-zsh" ]; then mv "${HOME}/.oh-my-zsh" "${HOME}/.oh-my-zsh_zimbackup" printf "${yellow}Oh-My-Zsh detected and backed up to\ ${HOME}/.oh-my-zsh_zimbackup${normal}\n" printf "${blue}This is done to prevent framework conflicts.${normal}\n" elif [ -d "${HOME}/.zplug" ]; then mv "${HOME}/.zplug" "${HOME}/.zplug_zimbackup" printf "${yellow}Zplug detected and backed up to\ ${HOME}/.zplug_zimbackup${normal}\n" printf "${blue}This is done to prevent framework conflicts.${normal}\n" elif [ -d "${HOME}/.zprezto" ]; then mv "${HOME}/.zprezto" "${HOME}/.zprezto_zimbackup" printf "${yellow}Prezto detected and backed up to\ ${HOME}/.zprezto_zimbackup${normal}\n" printf "${blue}This is done to prevent framework conflicts.${normal}\n" else : # Do nothing fi # Prevent the cloned repository from having insecure permissions. umask g-w,o-w # The Windows (MSYS) Git is not compatible with normal use on cygwin if [ "${OSTYPE}" = "cygwin" ]; then if git --version | grep msysgit >/dev/null; then printf "${red}Error: Windows/MSYS Git is not supported on Cygwin${normal}\n" printf "${red}Error: Make sure the Cygwin git package is installed and is first on the path${normal}\n" exit 1 fi fi # Back-up old zsh dotfiles if [ -f "${HOME}/.zshrc" ] || [ -L "${HOME}/.zshrc" ]; then printf "${yellow}Found ${HOME}/.zshrc! ${blue}Backing up to ${HOME}/.zshrc_zimbackup.${normal}\n" mv "${HOME}/.zshrc" "${HOME}/.zshrc_zimbackup" fi if [ -f "${HOME}/.zlogin" ] || [ -L "${HOME}/.zlogin" ]; then printf "${yellow}Found ${HOME}/.zlogin!$ ${blue}Backing up to ${HOME}/.zlogin_zimbackup${normal}\n" mv "${HOME}/.zlogin" "${HOME}/.zlogin_zimbackup" fi # Place template files in ~/ cp -a "${HOME}/.zim/templates/" "${HOME}/" # If this user's login shell is not already "zsh", attempt to switch if [ ! "$(expr "${SHELL}" : '.*/\(.*\)')" = "zsh" ]; then # Auto-change shell if platform provides "chsh" command if hash chsh >/dev/null 2>&1; then printf "${blue}Changing your default shell to zsh!${normal}\n" chsh -s $(grep "/zsh$" "/etc/shells" | tail -1) # If not, suggest user do so manually. else printf "${yellow}I can't change your shell automatically because this system does not have chsh.${normal}\n" printf "${yellow}Please manually change your default shell to zsh!${normal}\n" fi fi Z="${red}Z${green}" printf "${green} ______ _ _____ __ __ _ ${normal}\n" printf "${green} |$Z$Z$Z$Z$Z/ | | |$Z$Z$Z$Z$Z|$Z$Z\/$Z$Z| | |${normal}\n" printf "${green} /$Z/ ___| |__ |$Z| |$Z\\$Z$Z/$Z|_ __ _ __ _____ _____ __| | ${normal}\n" printf "${green} /$Z/ / __| '_ \ |$Z| |$Z|\/|$Z| '_ \| '__/ _ \ \ / / _ \/ _\` | ${normal}\n" printf "${green} /$Z/__\__ | | | | _|$Z|_|$Z| |$Z| |_) | | | (_) \ V | __| (_| | ${normal}\n" printf "${green} /$Z$Z$Z$Z$Z|___|_| |_| |$Z$Z$Z$Z$Z|$Z| |$Z| .__/|_| \___/ \_/ \___|\__,_| ${normal}\n" printf "${green} | | ${normal}\n" printf "${green} |_| ${normal}\n" unset Z # For archival purposes # ______ _ _____ __ __ _ # |___ / | | |_ _|| \/ | | | # / / ___ | |__ | | | \ / | _ __ _ __ ___ __ __ ___ __| | # / / / __|| '_ \ | | | |\/| || '_ \ | '__|/ _ \\ \ / // _ \ / _` | # / /__ \__ \| | | | _| |_ | | | || |_) || | | (_) |\ V /| __/| (_| | # /_____||___/|_| |_| |_____||_| |_|| .__/ |_| \___/ \_/ \___| \__,_| # | | # |_| # Remind user to copy back old settings if [ -f "${HOME}/.zshrc_zimbackup" ] || [ -L "${HOME}/.zshrc_zimbackup" ]; then printf "${yellow}Please inspect ${HOME}/.zshrc_zimbackup and copy over${normal}\n" printf "${yellow}wanted settings to ${HOME}/.zshrc${normal}\n" fi if [ -f "${HOME}/.zlogin_zimbackup" ] || [ -L "${HOME}/.zlogin_zimbackup" ]; then printf "${yellow}Please inspect ${HOME}/.zlogin_zimbackup and copy over${normal}\n" printf "${yellow}wanted settings to ${HOME}/.zlogin${normal}\n" fi # Load zsh env zsh } main