Created
March 19, 2020 22:07
-
-
Save iiiw/403e86e97d09ff1018a78b2a92bec2c7 to your computer and use it in GitHub Desktop.
Update neovim script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# vim: ft=sh | |
set -o errexit | |
set -o pipefail | |
pushd . >/dev/null | |
command -v git >/dev/null 2>&1 \ | |
|| { echo "$0: git must be installed" >&2; exit 1; } | |
# Unset Lua environment to not interfere in the build process. | |
l_path="$LUA_PATH" | |
l_cpath="$LUA_CPATH" | |
restore_luapath () { | |
[[ -z "$l_path" || -z "$l_cpath" ]] && return # no Lua to restore | |
export LUA_PATH="$l_path" | |
export LUA_CPATH="$l_cpath" | |
} | |
trap restore_luapath EXIT | |
unset LUA_PATH | |
unset LUA_CPATH | |
# Update repo | |
SRC_DIR="$HOME/src/neovim" | |
[[ -d "$SRC_DIR/.git" ]] \ | |
|| { echo "$0: cannot find git repo ~/src/neovim, aborting" >&2; exit 1; } | |
echo "> Updating neovim repo in $SRC_DIR" | |
cd "$SRC_DIR" | |
git pull origin | |
git checkout master | |
# Clean up | |
echo "> Cleaning up old build artefacts ..." | |
make distclean | |
# Build dependencies | |
echo "> Building dependencies in $SRC_DIR/.deps ..." | |
make_tool="make" | |
cmake_generator="Unix Makefiles" | |
if command -v ninja >/dev/null 2>&1; then | |
make_tool="ninja" # recommended | |
cmake_generator="Ninja" | |
fi | |
mkdir -p "$SRC_DIR/.deps" && cd "$SRC_DIR/.deps" | |
cmake -G "$cmake_generator" "$SRC_DIR/third-party" | |
"$make_tool" | |
# Install | |
echo "> Building and installing neovim ..." | |
cd "$SRC_DIR" | |
make CMAKE_BUILD_TYPE=Release | |
sudo make install # default /usr/local | |
# Restore Lua environment | |
restore_luapath | |
popd | |
nvim_v="$(nvim --version)" | |
echo "> Sucessfully installed ${nvim_v%%$'\n'*}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment