11#! /usr/bin/env bash
22
33# If anything fails, exit
4- set -eo pipefail
4+ set -eouE pipefail
5+
6+ SCRIPTS_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd) "
7+
8+ # shellcheck source=SCRIPTDIR/utils/core.sh
9+ source " ${SCRIPTS_DIR} /utils/core.sh"
10+ # shellcheck source=SCRIPTDIR/utils/api.sh
11+ source " ${SCRIPTS_DIR} /utils/api.sh"
12+ # shellcheck source=SCRIPTDIR/utils/neovim.sh
13+ source " ${SCRIPTS_DIR} /utils/neovim.sh"
14+
15+ download_neovim_script=" $SCRIPTS_DIR /neovim_download.sh"
516
617# Create a temporary directory to handle any remote nvim data location things
718temp_dir=$( mktemp -d 2> /dev/null || mktemp -d -t ' neovim_download' )
3344# Function to check if Neovim is available in the system's $PATH
3445function check_neovim_in_path() {
3546 if command -v nvim & > /dev/null; then
36- echo " Neovim already on PATH. Skipping installation..."
47+ info " Neovim already on PATH. Skipping installation..."
3748 exit 0
3849 fi
3950}
@@ -45,7 +56,7 @@ function link_to_system_neovim() {
4556 mkdir -p " $nvim_version_dir " /bin
4657 ln -sf " $( which nvim) " " $nvim_binary "
4758 else
48- echo " Error: Did not find Neovim on the path"
59+ error " Error: Did not find Neovim on the path"
4960 exit 1
5061 fi
5162}
@@ -55,7 +66,7 @@ function build_from_source() {
5566 local nvim_release_name=" nvim-$1 -source.tar.gz"
5667
5768 if [ ! -e " $nvim_version_dir /$nvim_release_name " ]; then
58- echo " Expected release to be present at $nvim_version_dir /$nvim_release_name . Aborting..."
69+ error " Expected release to be present at $nvim_version_dir /$nvim_release_name . Aborting..."
5970 exit 1
6071 fi
6172
@@ -82,31 +93,25 @@ function build_from_source() {
8293
8394# Install on Linux using AppImage
8495function setup_neovim_linux_appimage() {
85- local version=" $1 "
86- local nvim_release_name=" nvim-$1 -linux.appimage"
96+ local version=" $1 " arch_type=" $2 "
8797 local nvim_appimage_temp_path=" $temp_dir /$nvim_release_name "
8898
89- set +e # Prevent termination based on compare_version's return
90- compare_versions " $version " v0.10.3
91- local result=$?
92- set -e # Re-enable termination based on return values
93-
94- if [[ $version == " nightly" ]] || [[ $version == " stable" ]] || [[ $result -eq 1 ]]; then
95- nvim_release_name=" nvim-$1 -linux-$2 .appimage"
96- fi
99+ local nvim_release_name
100+ download_url=$( safe_subshell build_github_uri " $version " " Linux" " $arch_type " )
101+ nvim_release_name=$( basename " $download_url " )
97102
98103 if [ ! -e " $nvim_version_dir /$nvim_release_name " ]; then
99- echo " Expected release to be present at $nvim_version_dir /$nvim_release_name . Aborting..."
104+ error " Expected release to be present at $nvim_version_dir /$nvim_release_name . Aborting..."
100105 exit 1
101106 fi
102107
103108 cp " $nvim_version_dir /$nvim_release_name " " $nvim_appimage_temp_path "
104109
105- echo " Extracting Neovim binary..."
110+ info " Extracting Neovim binary..."
106111 chmod u+x " $nvim_appimage_temp_path "
107112 " $nvim_appimage_temp_path " --appimage-extract > /dev/null
108113
109- echo " Finishing up installing Neovim..."
114+ info " Finishing up installing Neovim..."
110115 mkdir -p " $nvim_version_dir " /bin
111116 mv -f " $temp_dir /squashfs-root" /* " $nvim_version_dir "
112117 ln -sf " $nvim_version_dir " /usr/bin/nvim " $nvim_binary "
@@ -149,61 +154,62 @@ function setup_neovim_macos() {
149154function install_neovim() {
150155 # Check if the specified download directory exists
151156 if [[ ! -d $remote_nvim_dir ]]; then
152- echo " Remote neovim directory does not exist. Creating it now..."
157+ info " Remote neovim directory does not exist. Creating it now..."
153158 mkdir -p " $remote_nvim_dir "
154159 fi
160+
155161 nvim_download_dir=" $remote_nvim_dir /nvim-downloads"
156162
157163 # Check if the specified release is already downloaded
158164 nvim_version_dir=" $nvim_download_dir /$nvim_version "
159165 nvim_binary=" $nvim_version_dir /bin/nvim"
160166
161167 if [[ ! $force_installation && -d $nvim_version_dir && $( $nvim_binary -v 2> /dev/null | head -c1 | wc -c) -ne 0 ]]; then
162- echo " Neovim ${nvim_version} is already installed. Skipping installation."
168+ info " Neovim ${nvim_version} is already installed. Skipping installation."
163169 else
164170 mkdir -p " $nvim_version_dir "
165171
166172 if [[ -f $nvim_binary && $( $nvim_binary -v 2> /dev/null | head -c1 | wc -c) -eq 0 ]]; then
167- echo " Neovim installation is corrupted. Would re-install..."
173+ warn " Neovim installation is corrupted. Would re-install..."
168174 fi
169175
170176 local os
171177 os=$( uname)
172178
173179 if [[ $install_method == " binary" ]]; then
174180 if [ " $offline_mode " == true ]; then
175- echo " Operating in offline mode. Will not download Neovim release"
181+ info " Operating in offline mode. Will not download Neovim release"
176182 else
177183 " $download_neovim_script " -o " $os " -v " $nvim_version " -d " $nvim_version_dir " -t " binary" -a " $arch_type "
178184 fi
179185
180186 # Install Neovim based on the detected OS
181187 if [[ $os == " Linux" ]]; then
182- setup_neovim_linux_appimage " $nvim_version " " $arch_type "
188+ safe_subshell setup_neovim_linux_appimage " $nvim_version " " $arch_type "
183189 elif [[ $os == " Darwin" ]]; then
184- setup_neovim_macos " $nvim_version " " $arch_type "
190+ safe_subshell setup_neovim_macos " $nvim_version " " $arch_type "
185191 else
186192 echo " Unsupported operating system: $( uname) "
187193 exit 1
188194 fi
189195 elif [[ $install_method == " source" ]]; then
190196 if [ " $offline_mode " == true ]; then
191- echo " Operating in offline mode. Will not download Neovim source"
197+ info " Operating in offline mode. Will not download Neovim source"
192198 else
193199 " $download_neovim_script " -o " $os " -v " $nvim_version " -d " $nvim_version_dir " -t " source" -a " $arch_type "
194200 fi
195- build_from_source " $nvim_version "
201+ safe_subshell build_from_source " $nvim_version "
196202 # Handle tar file downloaded or copied over
197203 elif [[ $install_method == " system" ]]; then
198204 # Handle symlinking to the system binary version
199- link_to_system_neovim
205+ safe_subshell link_to_system_neovim
200206 else
201- echo " Unsupported Neovim installation method. Available installation methods are: binary, source or system"
207+ error " Unsupported Neovim installation method. Available installation methods are: binary, source or system"
202208 exit 1
203209 fi
204210 fi
205211
206- echo " Neovim $nvim_version can be accessed at $nvim_binary "
212+ info " Neovim $nvim_version can be accessed at $nvim_binary "
207213}
208214
209215# Parse command-line options
@@ -254,10 +260,5 @@ if [[ $install_method == "system" && $nvim_version != "system" ]]; then
254260 exit 1
255261fi
256262
257- SCRIPT_DIR=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd)
258- download_neovim_script=" $SCRIPT_DIR /neovim_download.sh"
259- # shellcheck source=./scripts/neovim_utils.sh
260- source " ${SCRIPT_DIR} /neovim_utils.sh"
261-
262263cd " $temp_dir " || exit 1
263- install_neovim
264+ safe_subshell install_neovim
0 commit comments