diff --git a/README.md b/README.md index f949db6ff..e19076c69 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,10 @@ * [Features](#features) * [For whom?](#for-whom) * [Install](#install) + * [Prerequisites](#prerequisites) * [Linux and macOS](#linux-and-macos) + * [one-line installer](#one-line-installer) * [`Makefile`](#makefile) - * [`install.sh`](#installsh) * [Windows](#windows) * [Manual (Linux and macOS)](#manual-linux-and-macos) * [Customize](#customize) @@ -89,6 +90,8 @@ If you have been a vimmer for quite a while, just pick out the part you are inte ## Install +### Prerequisites + Make sure you have installed: - **git** @@ -100,6 +103,11 @@ The most recent Vim(NeoVim) version is recommended. ### Linux and macOS +#### one-line installer + +```bash +$ bash <(curl -fsSL https://raw.githubusercontent.com/liuchengxu/space-vim/master/install.sh) +``` #### `Makefile` ```bash @@ -109,26 +117,6 @@ $ make vim # install space-vim for Vim $ make neovim # install space-vim for NeoVim ``` -#### `install.sh` - -- curl - - ```bash - $ sh -c "$(curl -fsSL https://raw.githubusercontent.com/liuchengxu/space-vim/master/install.sh)" - ``` - -- wget - - ```bash - $ sh -c "$(wget -qO- https://raw.githubusercontent.com/liuchengxu/space-vim/master/install.sh)" - ``` - - :warning: For neovim, after the quick installer is done, you still need to create a symlink: - - ```bash - $ ln -s ~/.space-vim/init.vim ~/.config/nvim/init.vim - ``` - ### Windows 1. [Download git](https://git-scm.com/download/win) diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index 031a72734..bd30eeb3c --- a/install.sh +++ b/install.sh @@ -1,28 +1,20 @@ #!/usr/bin/env bash -# This setup file is based on spf13-vim's bootstrap.sh. -# Thanks for spf13-vim. - -app_name='space-vim' -dot_spacevim="$HOME/.spacevim" - -[ -z "$APP_PATH" ] && APP_PATH="$HOME/.space-vim" -[ -z "$REPO_URI" ] && REPO_URI='https://github.com/liuchengxu/space-vim.git' -[ -z "$REPO_BRANCH" ] && REPO_BRANCH='master' - -debug_mode='0' - -[ -z "$VIM_PLUG_PATH" ] && VIM_PLUG_PATH="$HOME/.vim/autoload" -[ -z "$VIM_PLUG_URL" ] && VIM_PLUG_URL='https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' - -########## Basic setup tools +app_name="space-vim" +repo_uri="https://github.com/liuchengxu/space-vim.git" +repo_name="space-vim" +repo_path="$HOME/.space-vim" +repo_branch="master" + +############################### +## Basic tools +############################### msg() { printf '%b\n' "$1" >&2 } success() { - if [ "$ret" -eq '0' ]; - then + if [ "$ret" -eq '0' ]; then msg "\33[32m[✔]\33[0m ${1}${2}" fi } @@ -32,65 +24,11 @@ error() { exit 1 } -debug() { - if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; - then - msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that." - fi -} - exists() { command -v "$1" >/dev/null 2>&1 } -program_exists() { - local ret='0' - exists "$1" || { local ret='1'; } - - # fail on non-zero return value - if [ "$ret" -ne 0 ]; - then - return 1 - fi - - return 0 -} - -program_must_exist() { - - # throw error on non-zero return value - if ! program_exists "$1"; then - error "You must have '$1' installed to continue." - fi -} - -lnif() { - if [ -e "$1" ]; then - ln -sf "$1" "$2" - fi - ret="$?" - debug -} - -########## Setup function -backup() { - if [ -e "$1" ]; then - msg "Attempting to back up your original vim configuration." - today=$(date +%Y%m%d_%s) - mv -v "$1" "$1.$today" - - ret="$?" - success "Your original vim configuration has been backed up." - debug - fi -} - sync_repo() { - local repo_path="$1" - local repo_uri="$2" - local repo_branch="$3" - local repo_name="$4" - if [ ! -e "$repo_path" ]; then msg "\033[1;34m==>\033[0m Trying to clone $repo_name" mkdir -p "$repo_path" @@ -103,73 +41,110 @@ sync_repo() { ret="$?" success "Successfully updated $repo_name" fi - - debug } -create_symlinks() { - local source_path="$1" - local target_path="$2" - - lnif "$source_path/init.vim" "$target_path/.vimrc" - +install_plugins() { + for exe in "$@"; do + eval "$exe +PlugInstall +qall" + done ret="$?" - success "Setting up vim symlinks." - - debug + success "Successfully installed plugins via vim-plug" } -sync_vim_plug() { - if [ ! -f "$VIM_PLUG_PATH/plug.vim" ]; then - curl -fLo "$1/plug.vim" --create-dirs "$2" - fi +generate_dot_spacevim() { + if [ ! -f "$HOME/.spacevim" ]; then + cp "$HOME/.space-vim/init.spacevim" "$HOME/.spacevim" - debug + ret="$?" + success "Successfully generated .spacevim in your home directory" + fi } -setup_vim_plug() { - local system_shell="$SHELL" - export SHELL='/bin/sh' - - vim \ - "+PlugInstall!" \ - "+PlugClean" \ - "+qall" - - export SHELL="$system_shell" - - success "Now updating/installing plugins using vim-plug" - - debug -} +backup() { + if [ -e "$1" ]; then + echo + msg "\033[1;34m==>\033[0m Attempting to back up your original vim configuration" + today=$(date +%Y%m%d_%s) + mv -v "$1" "$1.$today" -generate_dot_spacevim() { - if [ ! -f "$dot_spacevim" ]; then - cp "$APP_PATH/init.spacevim" "$dot_spacevim" + ret="$?" + success "Your original vim configuration has been backed up" fi - - debug } -########## Main() -program_must_exist "vim" -program_must_exist "git" - -backup "$HOME/.vimrc" +install_for_vim() { + backup "$HOME/.vimrc" + msg "\033[1;34m==>\033[0m Trying to download vim-plug" + curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + ret="$?" + success "Successfully downloaded vim-plug" -sync_repo "$APP_PATH" \ - "$REPO_URI" \ - "$REPO_BRANCH" \ - "$app_name" + ln -sf "$HOME/.space-vim/init.vim" "$HOME/.vimrc" + generate_dot_spacevim -create_symlinks "$APP_PATH" \ - "$HOME" + install_plugins "vim" +} -sync_vim_plug "$VIM_PLUG_PATH" \ - "$VIM_PLUG_URL" +install_for_neovim() { + backup "$HOME/.config/nvim/init.vim" + msg "\033[1;34m==>\033[0m Trying to download vim-plug" + curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + ret="$?" + success "Successfully downloaded vim-plug" -generate_dot_spacevim + mkdir -p "$HOME/.config/nvim" + ln -sf "$HOME/.space-vim/init.vim" "$HOME/.config/nvim/init.vim" + generate_dot_spacevim -setup_vim_plug + install_plugins "nvim" +} -msg "\nThanks for installing \033[1;31m$app_name\033[0m. Enjoy!" +############################### +## main +############################### +if ! exists "git"; then + error "You must have 'git' installed to continue." +fi + +sync_repo + +if exists "vim" && exists "nvim"; then + echo "\033[1;34m==>\033[0m Find both 'vim' and 'nvim' in your system" + echo + while true; do + read -r -p " Install space-vim for: [0]vim [1]nvim [2]vim and nvim :" opt + case $opt in + 0) + install_for_vim + break + ;; + 1) + install_for_neovim + break + ;; + 2) + install_for_vim + install_for_neovim + break + ;; + *) + echo "Please answer 0, 1 or 2" + ;; + esac + done +elif exists "vim"; then + msg "\033[1;34m==>\033[0m Only find 'vim' in your system" + msg " Starting to install space-vim for 'vim'" + install_for_vim +elif exists "nvim"; then + msg "\033[1;34m==>\033[0m Only find 'nvim' in your system" + msg " Starting to install space-vim for 'nvim'" + echo + install_for_neovim +else + error "You must have 'vim' or 'nvim' installed to continue" +fi + +msg "\nThanks for installing \033[1;31m$app_name\033[0m. Enjoy!" diff --git a/uninstall.sh b/uninstall.sh old mode 100644 new mode 100755 index fb428d294..e5662ce01 --- a/uninstall.sh +++ b/uninstall.sh @@ -13,8 +13,10 @@ confirm() { } uninstall() { - rm -f "${HOME}/.vimrc" - rm -rf "${HOME}/.space-vim" + rm -f "$HOME/.vimrc" + rm -f "$HOME/.config/nvim/init.vim" + rm -f "$HOME/.spacevim" + rm -rf "$HOME/.space-vim" } if confirm " - Uninstall (y/n) ? "; then