From 02b15f057fa72e16d660ae21339efc689dc61288 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 8 Jan 2021 22:53:21 +0800 Subject: [PATCH] Update nvim setup script --- docs/Nvim_setup.sh | 58 ++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/docs/Nvim_setup.sh b/docs/Nvim_setup.sh index 8c2c4ac..a6cbebd 100755 --- a/docs/Nvim_setup.sh +++ b/docs/Nvim_setup.sh @@ -7,7 +7,7 @@ PYTHON_INSTALLED=true # If Python has been installed, then we need to know whether Python is provided # by the system, or you have already installed Python under your HOME. -SYSTEM_PYTHON=true +SYSTEM_PYTHON=false # If SYSTEM_PYTHON is false, we need to decide whether to install # Anaconda (INSTALL_ANACONDA=true) or Miniconda (INSTALL_ANACONDA=false) @@ -16,6 +16,10 @@ INSTALL_ANACONDA=false # Whether to add the path of the installed executables to system PATH ADD_TO_SYSTEM_PATH=true +# select which shell we are using +USE_ZSH_SHELL=true +USE_BASH_SHELL=false + if [[ ! -d "$HOME/packages/" ]]; then mkdir -p "$HOME/packages/" fi @@ -27,21 +31,21 @@ fi ####################################################################### # Anaconda or miniconda install # ####################################################################### +if [[ "$INSTALL_ANACONDA" = true ]]; then + CONDA_DIR=$HOME/tools/anaconda + CONDA_NAME=Anaconda.sh + CONDA_LINK="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2019.10-Linux-x86_64.sh" +else + CONDA_DIR=$HOME/tools/miniconda + CONDA_NAME=Miniconda.sh + CONDA_LINK="https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh" +fi + if [[ ! "$PYTHON_INSTALLED" = true ]]; then echo "Installing Python in user HOME" SYSTEM_PYTHON=false - if [[ "$INSTALL_ANACONDA" = true ]]; then - CONDA_DIR=$HOME/tools/anaconda - CONDA_NAME=Anaconda.sh - CONDA_LINK="https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh" - else - CONDA_DIR=$HOME/tools/miniconda - CONDA_NAME=Miniconda.sh - CONDA_LINK="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" - fi - echo "Downloading and installing conda" if [[ ! -f "$HOME/packages/$CONDA_NAME" ]]; then @@ -55,18 +59,16 @@ if [[ ! "$PYTHON_INSTALLED" = true ]]; then bash "$HOME/packages/$CONDA_NAME" -b -p "$CONDA_DIR" # Setting up environment variables - if [[ "$ADD_TO_SYSTEM_PATH" = true ]]; then + if [[ "$ADD_TO_SYSTEM_PATH" = true ]] && [[ "$USE_BASH_SHELL" = true ]]; then echo "export PATH=\"$CONDA_DIR/bin:\$PATH\"" >> "$HOME/.bash_profile" fi - source "$HOME/.bash_profile" else echo "Python is already installed. Skip installing it." fi - # Install some Python packages used by Neovim plugins. echo "Installing Python packages" -PY_PACKAGES="pynvim python-language-server[all] black vim-vint" +declare -a py_packages=("pynvim" 'python-language-server[all]' "black" "vim-vint") if [[ "$SYSTEM_PYTHON" = true ]]; then echo "Using system Python to install $(PY_PACKAGES)" @@ -74,10 +76,14 @@ if [[ "$SYSTEM_PYTHON" = true ]]; then # If we use system Python, we need to install these Python packages under # user HOME, since we do not have permissions to install them under system # directories. - pip install --user $PY_PACKAGES + for p in "${py_packages[@]}"; do + pip install --user "$p" + done else echo "Using custom Python to install $(PY_PACKAGES)" - pip install $PY_PACKAGES + for p in "${py_packages[@]}"; do + "$CONDA_DIR/bin/pip" install "$p" + done fi @@ -87,7 +93,7 @@ fi RIPGREP_DIR=$HOME/tools/ripgrep RIPGREP_SRC_NAME=$HOME/packages/ripgrep.tar.gz RIPGREP_LINK="https://github.com/BurntSushi/ripgrep/releases/download/12.0.0/ripgrep-12.0.0-x86_64-unknown-linux-musl.tar.gz" -if [[ ! "$(command -v rg)" ]]; then +if [[ -z "$(command -v rg)" ]] && [[ ! -f "$RIPGREP_DIR/rg" ]]; then echo "Install ripgrep" if [[ ! -f $RIPGREP_SRC_NAME ]]; then echo "Downloading ripgrep and renaming" @@ -101,7 +107,7 @@ if [[ ! "$(command -v rg)" ]]; then tar zxvf "$RIPGREP_SRC_NAME" -C "$RIPGREP_DIR" --strip-components 1 fi - if [[ "$ADD_TO_SYSTEM_PATH" = true ]]; then + if [[ "$ADD_TO_SYSTEM_PATH" = true ]] && [[ "$USE_BASH_SHELL" = true ]]; then echo "export PATH=\"$RIPGREP_DIR:\$PATH\"" >> "$HOME/.bash_profile" fi else @@ -121,14 +127,14 @@ if [[ ! -f "$CTAGS_DIR/bin/ctags" ]]; then mkdir -p "$CTAGS_SRC_DIR" else # Prevent an incomplete download. - rm -rf "$CTAGS_SRC_DIR/" + rm -rf "$CTAGS_SRC_DIR" fi - git clone $CTAGS_LINK $CTAGS_SRC_DIR && cd "$CTAGS_SRC_DIR" + git clone "$CTAGS_LINK" "$CTAGS_SRC_DIR" && cd "$CTAGS_SRC_DIR" ./autogen.sh && ./configure --prefix="$CTAGS_DIR" make -j && make install - if [[ "$ADD_TO_SYSTEM_PATH" = true ]]; then + if [[ "$ADD_TO_SYSTEM_PATH" = true ]] && [[ "$USE_BASH_SHELL" = true ]]; then echo "export PATH=\"$CTAGS_DIR/bin:\$PATH\"" >> "$HOME/.bash_profile" fi else @@ -158,7 +164,7 @@ if [[ ! -f "$NVIM_DIR/bin/nvim" ]]; then echo "Extracting neovim" tar zxvf "$NVIM_SRC_NAME" --strip-components 1 -C "$NVIM_DIR" - if [[ "$ADD_TO_SYSTEM_PATH" = true ]]; then + if [[ "$ADD_TO_SYSTEM_PATH" = true ]] && [[ "$USE_BASH_SHELL" = true ]]; then echo "export PATH=\"$NVIM_DIR/bin:\$PATH\"" >> "$HOME/.bash_profile" fi else @@ -167,13 +173,15 @@ fi echo "Setting up config and installing plugins" if [[ -d "$NVIM_CONFIG_DIR" ]]; then - mv "$NVIM_CONFIG_DIR" $NVIM_CONFIG_DIR.backup + mv "$NVIM_CONFIG_DIR" "$NVIM_CONFIG_DIR.backup" fi git clone https://github.com/jdhao/nvim-config.git "$NVIM_CONFIG_DIR" echo "Installing vim-plug" -curl -fLo "$NVIM_SITE_DIR/autoload/plug.vim" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim +curl -fLo "$NVIM_SITE_DIR/autoload/plug.vim" --create-dirs https://cdn.jsdelivr.net/gh/junegunn/vim-plug/plug.vim + +echo "Installing plugins" "$NVIM_DIR/bin/nvim" +PlugInstall +qall echo "Finished installing Neovim and its dependencies!"