Skip to content

Instantly share code, notes, and snippets.

@holly
Created February 28, 2026 11:44
Show Gist options
  • Select an option

  • Save holly/cd5fdfb0c8e08f48dbaba071b1b58909 to your computer and use it in GitHub Desktop.

Select an option

Save holly/cd5fdfb0c8e08f48dbaba071b1b58909 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
set -C
ARCH=$(uname -m)
LOCAL_DIR=/usr/local
DOWNLOAD_URL="https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-${ARCH}.tar.gz"
EXPANDED_DIR=$(basename $DOWNLOAD_URL | sed -e 's/.tar.gz$//')
INSTALL_DIR="${LOCAL_DIR}/${EXPANDED_DIR}"
INSTALL_PATH="${LOCAL_DIR}/bin/nvim"
_is_root() {
if [[ $(id -u) -eq 0 ]]; then
return 0
else
return 1
fi
}
_execute() {
local BASH=$(which bash)
if ! _is_root; then
BASH="sudo $BASH"
fi
$BASH -c "$@"
}
install() {
if [[ -d $INSTALL_DIR ]]; then
echo "$INSTALL_DIR is already exists."
exit 1
fi
_execute "curl -sfL $DOWNLOAD_URL | tar -C $LOCAL_DIR -pxvzf -; (cd "${LOCAL_DIR}/bin"; ln -sf "../${EXPANDED_DIR}/bin/nvim" nvim)"
}
forceinstall() {
uninstall
echo "nvim force install."
echo ""
install
}
uninstall() {
if [[ ! -d $INSTALL_DIR ]]; then
echo "$INSTALL_DIR is not exists."
exit 1
fi
_execute "rm -frv $INSTALL_DIR $INSTALL_PATH"
}
usage() {
echo "Usage: $0 [install|forceinstall|uninstall]"
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
COMMAND=$1
case "$COMMAND" in
"install" ) install ;;
"forceinstall" ) forceinstall ;;
"uninstall" ) uninstall ;;
* ) usage;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment