forked from neoclide/coc.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·69 lines (60 loc) · 1.46 KB
/
install.sh
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
#!/bin/sh
set -o nounset # error when referencing undefined variable
set -o errexit # exit when command fails
BLUE="$(tput setaf 4 2>/dev/null || echo '')"
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
command_exists() {
command -v "$1" >/dev/null 2>&1;
}
fetch() {
local command
if hash curl 2>/dev/null; then
set +e
command="curl --fail -L $1"
curl --compressed --fail -L "$1"
rc=$?
set -e
else
if hash wget 2>/dev/null; then
set +e
command="wget -O- -q $1"
wget -O- -q "$1"
rc=$?
set -e
else
echo "No HTTP download program (curl, wget) found…"
exit 1
fi
fi
if [ $rc -ne 0 ]; then
echo "Command failed (exit code $rc): ${BLUE}${command}${NO_COLOR}"
exit $rc
fi
}
get_latest_release() {
fetch "https://api.github.com/repos/neoclide/coc.nvim/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
if [ $# -eq 0 ]; then
echo "Fetching latest release."
tag=$(get_latest_release)
else
tag=$1
fi
download() {
mkdir -p build
cd build
if [ "$tag" = "nightly" ]; then
fetch https://raw.githubusercontent.com/neoclide/coc.nvim/release/build/index.js > index.js
return
fi
url="https://github.com/neoclide/coc.nvim/releases/download/$tag/coc.tar.gz"
echo "Downloading binary from ${url}"
if fetch "${url}" | tar xzfv -; then
return
else
echo "Release not available for now, please wait for a few minutes."
fi
}
download