From 9f78da8736a6191ca62caae0eff169b6ad45d439 Mon Sep 17 00:00:00 2001 From: Chris DeLuca Date: Mon, 11 May 2015 17:30:27 -0400 Subject: [PATCH] Preliminary support for neovim A simple change to support neovim. Fixes #774. Move nvimrc file inside .nvim directory Only install neovim support if neovim is being used Use program_exists function instead of vimscript Made a hasty mistake and added vimscript to a bash script :X Neovim not existing no longer stops script Also correct `endif` to `fi`. Refactor program_exists naming Changed `program_exists` to `program_must_exist`, which throws an error which halts the script if the program is not found, and refactored `nvim_exists` to be the more general `program_exists`, which does not throw an error if the program is not found. Refactor program_exists and program_must_exist `program_must_exist` uses `program_exists` now, instead of repeating code. Changed `type` to `command -v` in `program_exists` to be more POSIX compliant. Refactored status code conditional in `program_exists` to remove double negatives. Thanks to @mkwmms for the suggestions. Preliminary support for neovim A simple change to support neovim. Fixes #774. Move nvimrc file inside .nvim directory Refactor program_exists naming Changed `program_exists` to `program_must_exist`, which throws an error which halts the script if the program is not found, and refactored `nvim_exists` to be the more general `program_exists`, which does not throw an error if the program is not found. Refactor program_exists and program_must_exist `program_must_exist` uses `program_exists` now, instead of repeating code. Changed `type` to `command -v` in `program_exists` to be more POSIX compliant. Refactored status code conditional in `program_exists` to remove double negatives. Thanks to @mkwmms for the suggestions. --- bootstrap.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index bcd89d2..0b6ef1e 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -47,10 +47,21 @@ debug() { program_exists() { local ret='0' - type $1 >/dev/null 2>&1 || { local ret='1'; } + command -v $1 >/dev/null 2>&1 || { local ret='1'; } + + # fail on non-zero return value + if [ "$ret" -ne 0 ]; then + return 1 + fi + + return 0 +} + +program_must_exist() { + program_exists $1 # throw error on non-zero return value - if [ ! "$ret" -eq '0' ]; then + if [ "$?" -ne 0 ]; then error "You must have '$1' installed to continue." fi } @@ -115,6 +126,11 @@ create_symlinks() { lnif "$source_path/.vimrc.before" "$target_path/.vimrc.before" lnif "$source_path/.vim" "$target_path/.vim" + if program_exists "nvim"; then + lnif "$source_path/.vim" "$target_path/.nvim" + lnif "$source_path/.vimrc" "$target_path/.nvim/nvimrc" + fi + touch "$target_path/.vimrc.local" ret="$?" @@ -160,8 +176,8 @@ setup_vundle() { ############################ MAIN() variable_set "$HOME" -program_exists "vim" -program_exists "git" +program_must_exist "vim" +program_must_exist "git" do_backup "$HOME/.vim" \ "$HOME/.vimrc" \