blob: eab8521e5ebc437e41b6e1779850dd0f54cc80c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
#!/bin/bash
# Created By: srdusr
# Created On: Sat 12 Aug 2023 13:11:39 CAT
# Project: Install/update/downgrade/change version/uninstall Neovim script, primarily for Linux but may work in other platforms
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Function to handle errors
handle_error() {
local message="$1"
printf "${RED}Error: $message${NC}\n"
}
# Check if necessary dependencies are installed
check_dependencies() {
if [ -x "$(command -v wget)" ]; then
DOWNLOAD_COMMAND="wget"
elif [ -x "$(command -v curl)" ]; then
DOWNLOAD_COMMAND="curl"
else
printf "${RED}Error: Neither wget nor curl found. Please install one of them to continue!${NC}\n"
exit 1
fi
}
# Check for privilege escalation tools
check_privilege_tools() {
if [ -x "$(command -v sudo)" ]; then
PRIVILEGE_TOOL="sudo"
elif [ -x "$(command -v doas)" ]; then
PRIVILEGE_TOOL="doas"
elif [ -x "$(command -v pkexec)" ]; then
PRIVILEGE_TOOL="pkexec"
elif [ -x "$(command -v dzdo)" ]; then
PRIVILEGE_TOOL="dzdo"
elif [ "$(id -u)" -eq 0 ]; then
PRIVILEGE_TOOL="" # root
else
PRIVILEGE_TOOL="" # No privilege escalation mechanism found
printf "\n${RED}Error: No privilege escalation tool (sudo, doas, pkexec, dzdo, or root privileges) found. You may not have sufficient permissions to run this script.${NC}\n"
printf "\nAttempt to continue Installation (might fail without a privilege escalation tool)? [yes/no] "
read continue_choice
case $continue_choice in
[Yy] | [Yy][Ee][Ss]) ;;
[Nn] | [Nn][Oo]) exit ;;
*) handle_error "Invalid choice. Exiting..." && exit ;;
esac
fi
}
# Check if Neovim is already installed
check_neovim_installed() {
if [ -x "$(command -v nvim)" ]; then
return 0 # Neovim is installed
else
return 1 # Neovim is not installed
fi
}
version_id=""
action=""
# Nightly version
nightly_version() {
local url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage"
install_neovim "$url"
version_id=$(echo "$url" | grep -oP 'v\d+\.\d+\.\d+')
}
# Stable version
stable_version() {
local url="https://github.com/neovim/neovim/releases/download/stable/nvim.appimage"
install_neovim "$url"
version_id=$(echo "$url" | grep -oP 'v\d+\.\d+\.\d+')
}
# Specific version
specific_version() {
local version="$1"
local url="https://github.com/neovim/neovim/releases/download/$version/nvim.appimage"
install_neovim "$url"
version_id=$(echo "$url" | grep -oP 'v\d+\.\d+\.\d+')
}
# Function to download a file using wget or curl
download_file() {
local url="$1"
local output="$2"
if [ "$DOWNLOAD_COMMAND" = "wget" ]; then
"$DOWNLOAD_COMMAND" -q --show-progress -O "$output" "$url"
elif [ "$DOWNLOAD_COMMAND" = "curl" ]; then
"$DOWNLOAD_COMMAND" --progress-bar -# -o "$output" "$url"
else
echo "Unsupported download command: $DOWNLOAD_COMMAND"
exit 1
fi
}
# Check if a specific version of Neovim exists
version_exists() {
local version="$1"
if [[ $version != v* ]]; then
version="v$version"
fi
local url="https://github.com/neovim/neovim/releases/tag/$version"
# Send a HEAD request and check the response status using wget or curl
if "$DOWNLOAD_COMMAND" /dev/null "$url" 2>/dev/null; then
return 0 # Version exists
else
return 1 # Version does not exist
fi
}
# Choose Version
choose_version() {
printf "${GREEN}Choose what version to install...${NC}\n"
valid_choice=false
while [ "$valid_choice" = false ]; do
# Ask user for version preference
printf "Installation options:\n"
printf " 1. Nightly version (default)\n"
printf " 2. Stable version\n"
printf " 3. Specific version\n"
printf "Enter the number corresponding to your choice (1/2/3): "
read -r version_choice
case $version_choice in
1)
nightly_version
valid_choice=true
;;
2)
stable_version
valid_choice=true
;;
3)
# Ask user for specific version
read -p "Enter the specific version (e.g., v0.1.0): " specific_version
# Check if the specific version exists on GitHub releases
if version_exists "$specific_version"; then
# Install specific version
specific_version "$specific_version"
valid_choice=true
else
printf "${RED}The specified version $specific_version does not exist.${NC}\n"
fi
;;
*)
handle_error "Invalid choice. Please enter a valid option (1, 2, or 3)."
;;
esac
done
}
# Install Neovim
install_neovim() {
local url="$1"
local install_action="$2"
version_id="$3"
printf "Downloading and installing Neovim $version_id...\n"
# Determine the platform-specific installation steps
case "$(uname -s)" in
Linux)
printf "Detected Linux OS.\n"
if [ -x "$(command -v fusermount)" ]; then
printf "FUSE is available. Downloading and running the AppImage...\n"
download_file "$url" "nvim.appimage"
chmod u+x nvim.appimage
"$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim
"$PRIVILEGE_TOOL" mv nvim.appimage /usr/bin/nvim
else
printf "FUSE is not available. Downloading and extracting the AppImage...\n"
download_file "$url" "nvim.appimage"
chmod u+x nvim.appimage
./nvim.appimage --appimage-extract
"$PRIVILEGE_TOOL" cp squashfs-root/usr/bin/nvim /usr/local/bin
"$PRIVILEGE_TOOL" mv squashfs-root/usr/bin/nvim /usr/bin
fi
;;
Darwin)
printf "Detected macOS.\n"
download_file "$url" "nvim-macos.tar.gz"
xattr -c ./nvim-macos.tar.gz
tar xzvf nvim-macos.tar.gz
"$PRIVILEGE_TOOL" cp nvim-macos/bin/nvim /usr/local/bin
"$PRIVILEGE_TOOL" mv nvim-macos/bin/nvim /usr/bin/nvim
;;
MINGW*)
printf "Detected Windows.\n"
download_file "$url" "nvim.appimage"
chmod +x nvim.appimage
if [ "$PRIVILEGE_TOOL" = "sudo" ]; then
"$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim
"$PRIVILEGE_TOOL" mv /usr/local/bin/nvim /usr/bin
elif [ "$PRIVILEGE_TOOL" = "" ]; then
cp nvim.appimage /usr/local/bin/nvim
mv /usr/local/bin/nvim /usr/bin
else
printf "No privilege escalation tool found. Cannot install Neovim on Windows.\n"
fi
;;
*)
printf "Unsupported operating system.\n"
exit 1
;;
esac
if [ "$install_action" = "installed" ]; then
printf "${GREEN}Neovim $version_id has been installed successfully!${NC}\n"
fi
}
# Update Neovim to the latest version (nightly/stable)
update_version() {
printf "${GREEN}Updating Neovim to the latest version...${NC}\n"
valid_choice=false
while [ "$valid_choice" = false ]; do
# Determine which version to update to (nightly/stable)
printf "Select version to update to:\n"
printf " 1. Nightly\n"
printf " 2. Stable\n"
printf "Enter the number corresponding to your choice (1/2): "
read update_choice
case $update_choice in
1)
nightly_version
action="updated"
valid_choice=true
;;
2)
stable_version
action="updated"
valid_choice=true
;;
*)
handle_error "Invalid choice. Please enter a valid option (1 or 2)."
;;
esac
done
if [ "$action" = "updated" ]; then
printf "${GREEN}Neovim has been updated successfully to $version_id!${NC}\n"
fi
}
# Uninstall Neovim
uninstall_neovim() {
printf "${RED}Uninstalling Neovim...${NC}\n"
# Detect the operating system to determine the appropriate uninstallation method
case "$(uname -s)" in
Linux)
printf "Detected Linux OS.\n"
"$PRIVILEGE_TOOL" rm /usr/local/bin/nvim
"$PRIVILEGE_TOOL" rm /usr/bin/nvim
;;
Darwin)
printf "Detected macOS.\n"
"$PRIVILEGE_TOOL" rm /usr/local/bin/nvim
"$PRIVILEGE_TOOL" rm /usr/bin/nvim
;;
MINGW*)
printf "Detected Windows.\n"
if [ "$PRIVILEGE_TOOL" = "sudo" ]; then
"$PRIVILEGE_TOOL" rm /usr/local/bin/nvim
"$PRIVILEGE_TOOL" rm /usr/bin/nvim
else
[ "$PRIVILEGE_TOOL" = "" ]
rm /usr/local/bin/nvim
rm /usr/bin/nvim
fi
;;
*)
printf "Unsupported operating system.\n"
;;
esac
printf "${GREEN}Neovim has been uninstalled successfully!${NC}\n"
}
# Check if Neovim is running
check_neovim_running() {
if pgrep nvim >/dev/null; then
printf "${RED}Error: Neovim is currently running. Please close Neovim before proceeding.${NC}\n"
read -p "Do you want to forcefully terminate Neovim and continue? [yes/no] " terminate_choice
case $terminate_choice in
[Yy] | [Yy][Ee][Ss])
pkill nvim # Forcefully terminate Neovim
;;
[Nn] | [Nn][Oo])
echo "Exiting..."
exit 1
;;
*)
handle_error "Invalid choice."
;;
esac
fi
}
check_neovim_running
# Define the variable to control the prompt
SHOW_PROMPT=1
# Check if necessary dependencies are installed
check_dependencies
# Check for privilege escalation tools
check_privilege_tools
# Check if Neovim is already installed
if check_neovim_installed; then
printf "${GREEN}Neovim is already installed!${NC}\n"
else
choose_version
fi
# Function to check for updates and display breaking changes
check_version_updates() {
local latest_version_url="https://api.github.com/repos/neovim/neovim/releases/latest"
local latest_version=""
if [ -x "$(command -v curl)" ]; then
latest_version=$(curl -sSL "$latest_version_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
elif [ -x "$(command -v wget)" ]; then
latest_version=$(wget -qO - "$latest_version_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
printf "${RED}Error: Neither curl nor wget found. Please install one of them to continue!${NC}\n"
exit 1
fi
if version_exists "$latest_version"; then
printf "${GREEN}An update is available!${NC}\n"
display_breaking_changes "$latest_version"
else
printf "You have the latest version of Neovim.\n"
fi
}
# Function to display breaking changes for a specific version
display_breaking_changes() {
local version="$1"
local changelog_url="https://github.com/neovim/neovim/releases/tag/$version"
local changelog=""
if [ -x "$(command -v curl)" ]; then
changelog=$(curl -sSL "$changelog_url" | grep -oE '<h1>Breaking Changes.*?</ul>' | sed 's/<[^>]*>//g')
elif [ -x "$(command -v wget)" ]; then
changelog=$(wget -qO - "$changelog_url" | grep -oE '<h1>Breaking Changes.*?</ul>' | sed 's/<[^>]*>//g')
else
printf "${RED}Error: Neither curl nor wget found. Please install one of them to continue!${NC}\n"
exit 1
fi
printf "\nBreaking Changes in Neovim $version:\n"
printf "$changelog\n"
}
# Main loop
while [ "$SHOW_PROMPT" -gt 0 ]; do
printf "Select an action:\n"
printf " 1. Update Neovim\n"
printf " 2. Check for updates\n"
printf " 3. Change to a specific version\n"
printf " 4. Uninstall Neovim\n"
printf " 5. Run Neovim\n"
printf " 6. Exit\n"
read -p "Enter the number or 'q' to exit: " choice
case $choice in
1)
update_version
;;
2)
check_version_updates
;;
3)
choose_version
;;
4)
uninstall_neovim
;;
5)
nvim
;;
6 | [Qq])
echo "Exiting..."
exit
;;
*)
handle_error "Invalid choice. Please choose a valid option by entering the corresponding number or 'q' to 'exit'."
;;
esac
done
|