forked from zgpio/tree.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·84 lines (73 loc) · 1.85 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
set -o nounset # error when referencing undefined variable
set -o errexit # exit when command fails
BOLD="$(tput bold 2>/dev/null || echo '')"
GREY="$(tput setaf 0 2>/dev/null || echo '')"
BLUE="$(tput setaf 4 2>/dev/null || echo '')"
RED="$(tput setaf 1 2>/dev/null || echo '')"
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
YELLOW="$(tput setaf 3 2>/dev/null || echo '')"
error() {
printf "${RED} $@${NO_COLOR}\n" >&2
}
warn() {
printf "${YELLOW}! $@${NO_COLOR}\n"
}
info() {
printf "${BLUE} $@${NO_COLOR}\n"
}
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
error "No HTTP download program (curl, wget) found…"
exit 1
fi
fi
if [ $rc -ne 0 ]; then
error "Command failed (exit code $rc): ${BLUE}${command}${NO_COLOR}"
exit $rc
fi
}
get_latest_release() {
fetch "https://api.github.com/repos/zgpio/tree.nvim/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
if [ $# -eq 0 ]; then
info "Fetching latest release."
tag=$(get_latest_release)
else
tag=$1
fi
download() {
# mkdir -p bin
# cd bin
url="https://github.com/zgpio/tree.nvim/releases/download/$tag/${1}"
info "Downloading binary from ${url}"
if fetch "${url}" | tar xzfv - --strip-components 2; then
# chmod a+x ${1%.tar.gz}
return
else
warn "Binary not available for now, please wait for a few minutes."
fi
}
arch=$(uname -sm)
case "${arch}" in
"Linux x86_64") download tree-linux.tar.gz ;;
"Linux i686") download tree-linux.tar.gz ;;
"Darwin x86_64") download tree-macos.tar.gz ;;
*) info "No pre-built binary available for ${arch}.";;
esac