|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Use colors, but only if connected to a terminal, and that terminal |
| 4 | +# supports them. |
| 5 | +if which tput >/dev/null 2>&1; then |
| 6 | + ncolors=$(tput colors) |
| 7 | +fi |
| 8 | +if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then |
| 9 | + RED="$(tput setaf 1)" |
| 10 | + GREEN="$(tput setaf 2)" |
| 11 | + YELLOW="$(tput setaf 3)" |
| 12 | + BLUE="$(tput setaf 4)" |
| 13 | + BOLD="$(tput bold)" |
| 14 | + NORMAL="$(tput sgr0)" |
| 15 | +else |
| 16 | + RED="" |
| 17 | + GREEN="" |
| 18 | + YELLOW="" |
| 19 | + BLUE="" |
| 20 | + BOLD="" |
| 21 | + NORMAL="" |
| 22 | +fi |
| 23 | + |
| 24 | +ORG_NAME="ets-labs" |
| 25 | +REPO_NAME="python-vimrc" |
| 26 | +INIT_BASH_PATH="https://raw.githubusercontent.com/${ORG_NAME}/${REPO_NAME}/master/init.sh" |
| 27 | +VIMRC_URL="https://github.com/${ORG_NAME}/${REPO_NAME}.git" |
| 28 | +VUNDLE_URL="https://github.com/VundleVim/Vundle.vim.git" |
| 29 | +WOMBAT256MOD_URL="http://www.vim.org/scripts/download_script.php?src_id=13400" |
| 30 | +UPDATE_INTERVAL_DAYS=7 |
| 31 | + |
| 32 | +if [ ! -n "${VIM}" ]; then |
| 33 | + VIM=~/.vim |
| 34 | +fi |
| 35 | + |
| 36 | +HELLO_TEXT=$(cat <<HEREDOC |
| 37 | +
|
| 38 | + iiii |
| 39 | + i::::i |
| 40 | + iiii |
| 41 | +
|
| 42 | + vvvvvvv vvvvvvviiiiiii mmmmmmm mmmmmmm rrrrr rrrrrrrrr cccccccccccccccc |
| 43 | + v:::::v v:::::v i:::::i mm:::::::m m:::::::mm r::::rrr:::::::::r cc:::::::::::::::c |
| 44 | + v:::::v v:::::v i::::i m::::::::::mm::::::::::mr:::::::::::::::::r c:::::::::::::::::c |
| 45 | + v:::::v v:::::v i::::i m::::::::::::::::::::::mrr::::::rrrrr::::::rc:::::::cccccc:::::c |
| 46 | + v:::::v v:::::v i::::i m:::::mmm::::::mmm:::::m r:::::r r:::::rc::::::c ccccccc |
| 47 | + v:::::v v:::::v i::::i m::::m m::::m m::::m r:::::r rrrrrrrc:::::c |
| 48 | + v:::::v:::::v i::::i m::::m m::::m m::::m r:::::r c:::::c |
| 49 | + v:::::::::v i::::i m::::m m::::m m::::m r:::::r c::::::c ccccccc |
| 50 | + v:::::::v i::::::im::::m m::::m m::::m r:::::r c:::::::cccccc:::::c |
| 51 | + v:::::v i::::::im::::m m::::m m::::m r:::::r c:::::::::::::::::c |
| 52 | + v:::v i::::::im::::m m::::m m::::m r:::::r cc:::::::::::::::c |
| 53 | + vvv iiiiiiiimmmmmm mmmmmm mmmmmm rrrrrrr cccccccccccccccc |
| 54 | +
|
| 55 | +HEREDOC |
| 56 | +) |
| 57 | + |
| 58 | +is_git_exists() { |
| 59 | + hash git >/dev/null 2>&1 |
| 60 | +} |
| 61 | + |
| 62 | +install() { |
| 63 | + printf "${BLUE}%s${NORMAL}\n\n" "${HELLO_TEXT}" |
| 64 | + |
| 65 | + is_git_exists || { |
| 66 | + printf "${RED}%s${NORMAL}\n" "Error: git is not installed." |
| 67 | + exit 1 |
| 68 | + } |
| 69 | + |
| 70 | + if [ -d "${VIM}" ]; then |
| 71 | + printf "${YELLOW}%s${NORMAL}\n" "You already have ${VIM} directory." |
| 72 | + printf "${YELLOW}%s${NORMAL}\n" "You have to remove ${VIM} if you want to re-install." |
| 73 | + exit 0 |
| 74 | + fi |
| 75 | + |
| 76 | + # Prevent the cloned repository from having insecure permissions. Failing to do |
| 77 | + # so causes compinit() calls to fail with "command not found: compdef" errors |
| 78 | + # for users with insecure umasks (e.g., "002", allowing group writability). Note |
| 79 | + # that this will be ignored under Cygwin by default, as Windows ACLs take |
| 80 | + # precedence over umasks except for filesystems mounted with option "noacl". |
| 81 | + umask g-w,o-w |
| 82 | + |
| 83 | + printf "${GREEN}%s${NORMAL}\n" "Cloning vimrc from ${VIMRC_URL}" |
| 84 | + env git clone --depth=1 ${VIMRC_URL} ${VIM} || { |
| 85 | + printf "${RED}%s${NORMAL}\n" "Error: git clone of vimrc repo failed." |
| 86 | + exit 1 |
| 87 | + } |
| 88 | + |
| 89 | + printf "${BLUE}%s${NORMAL}\n" "Looking for an existing vim config..." |
| 90 | + if [ -f ~/.vimrc ] || [ -h ~/.vimrc ]; then |
| 91 | + printf "${YELLOW}%s${NORMAL}\n" "Found ~/.vimrc." |
| 92 | + printf "${BLUE}%s${NORMAL}\n" "You will see your old ~/.vimrc as ${VIM}/vimrc.bak" |
| 93 | + mv ~/.vimrc ${VIM}/vimrc.bak |
| 94 | + fi |
| 95 | + |
| 96 | + printf "${BLUE}%s${NORMAL}\n" "Symlinking ${VIM}/vimrc with ~/.vimrc..." |
| 97 | + ln -fs ${VIM}/vimrc ~/.vimrc |
| 98 | + |
| 99 | + if [ ! -d "$VIM/bundle/Vundle.vim" ]; then |
| 100 | + printf "${BLUE}%s${NORMAL}\n" "Installing Vundle..." |
| 101 | + env git clone --depth=1 ${VUNDLE_URL} "${VIM}/bundle/Vundle.vim" |
| 102 | + fi |
| 103 | + |
| 104 | + if [ ! -f ${VIM}/colors/wombat256mod.vim ]; then |
| 105 | + if [ ! -d ${VIM}/colors/ ]; then |
| 106 | + mkdir -p ${VIM}/colors |
| 107 | + fi |
| 108 | + wget ${WOMBAT256MOD_URL} -O ${VIM}/colors/wombat256mod.vim |
| 109 | + fi |
| 110 | + |
| 111 | + printf "${GREEN}%s${NORMAL}\n" "Vimrc has been configured ;)" |
| 112 | + printf "${YELLOW}%s${NORMAL}\n" "Do not worry about error messages. When it occurs just press enter and wait till all plugins are installed." |
| 113 | + printf "${BLUE}%s${NORMAL}\n" "Keep calm and use VIM!" |
| 114 | + |
| 115 | + vim +PluginInstall |
| 116 | +} |
| 117 | + |
| 118 | +help() { |
| 119 | + printf "${BLUE}%s${NORMAL}\n\n" "${HELLO_TEXT}" |
| 120 | + cat <<HEREDOC |
| 121 | + SYNOPSIS |
| 122 | + bash -c "\$(curl -fsSL ${INIT_BASH_PATH})" [install|help] |
| 123 | +
|
| 124 | +HEREDOC |
| 125 | +} |
| 126 | + |
| 127 | +case "${0}" in |
| 128 | + "install") |
| 129 | + install |
| 130 | + ;; |
| 131 | + "help") |
| 132 | + help |
| 133 | + ;; |
| 134 | +esac |
0 commit comments